0% found this document useful (0 votes)
47 views29 pages

VP Journal

The document contains 7 assignments for a C# programming lab course. Each assignment provides code examples to demonstrate different C# programming concepts like: 1) Printing output to the console 2) Defining multiple classes in a program 3) Passing value types and reference types by value and by reference 4) Type casting (implicit and explicit) 5) Boxing and unboxing value types 6) For each concept, the student provides the code and expected output.

Uploaded by

Tejas Hankare
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views29 pages

VP Journal

The document contains 7 assignments for a C# programming lab course. Each assignment provides code examples to demonstrate different C# programming concepts like: 1) Printing output to the console 2) Defining multiple classes in a program 3) Passing value types and reference types by value and by reference 4) Type casting (implicit and explicit) 5) Boxing and unboxing value types 6) For each concept, the student provides the code and expected output.

Uploaded by

Tejas Hankare
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

Name :-Tanuja Prakash Date.

Class :- BCA-III Sem : V Roll No. : 28


Subject : Lab Course Based On Paper No 505 (Visual Programming)

Assignment No. 1

• Write a c# program to display “hello CIMDR” and compile it with csc.exe.

using System;

namespace ConsoleApp2
{
class testclass
{
static void Main(string[] args)
{
System.Console.Write("Hello CIMDR");
System.Console.Write("Welcome To CIMDR");
System.Console.WriteLine("Batch BCA-III 2020-21");

}
}
}

Output:

BCA III SEM V Page 1


Name :-Tanuja Prakash Date.
Class :- BCA-III Sem : V Roll No. : 28
Subject : Lab Course Based On Paper No 505 (Visual Programming)

Assignment No. 2

• Write a c# program to display “class name”and compile it with csc.exe.

using System;

namespace ConsoleApp1
{
class first
{
static void Main(string[] args)
{
Console.WriteLine("This is 1st Class");
}
}

class second
{
static void main()
{
Console.WriteLine("This is 2nd Class");
}
}
class third
{
static void main()
{
Console.WriteLine("This is 3rd Class");
}
}
}

Output:

BCA III SEM V Page 2


Name :-Tanuja Prakash Date.
Class :- BCA-III Sem : V Roll No. : 28
Subject : Lab Course Based On Paper No 505 (Visual Programming)

BCA III SEM V Page 3


Name :-Tanuja Prakash Date.
Class :- BCA-III Sem : V Roll No. : 28
Subject : Lab Course Based On Paper No 505 (Visual Programming)

Assignment No. 3

• Write a c# program to display “Value Type”and compile it with csc.exe.

using System;

namespace ConsoleApp4
{
class Program
{
static void square(int a, int b)
{
a = a * a;
b = b * b;
Console.WriteLine(a + " " + b);
}
static void Main(string[] args)
{
int num1 = 5;
int num2 = 6;
Console.WriteLine(num1 + " " + num2);
square(num1, num2);
Console.WriteLine(num1 + " " + num2);
Console.WriteLine("Press Any Key to Exit...");
Console.ReadLine();
}
}
}
Output:

BCA III SEM V Page 4


Name :-Tanuja Prakash Date.
Class :- BCA-III Sem : V Roll No. : 28
Subject : Lab Course Based On Paper No 505 (Visual Programming)

BCA III SEM V Page 5


Name :-Tanuja Prakash Date.
Class :- BCA-III Sem : V Roll No. : 28
Subject : Lab Course Based On Paper No 505 (Visual Programming)

Assignment No. 4

• Write a c# program to display “Reference Type”and compile it with csc.exe.

using System;

namespace ConsoleApp5
{
class person
{
public int age;
}
class Program
{
static void square(person a, person b)
{
a.age = a.age * a.age;
b.age = b.age * b.age;
Console.WriteLine(a.age + " " + b.age);
}
static void Main(string[] args)
{
person p1 = new person();
person p2 = new person();
p1.age = 20;
p2.age = 21;
Console.WriteLine(p1.age + " " + p2.age);
square(p1, p2);
Console.WriteLine("Press Any Key to exit...");
Console.ReadLine();
}

BCA III SEM V Page 6


Name :-Tanuja Prakash Date.
Class :- BCA-III Sem : V Roll No. : 28
Subject : Lab Course Based On Paper No 505 (Visual Programming)

}
}

Output :

BCA III SEM V Page 7


Name :-Tanuja Prakash Date.
Class :- BCA-III Sem : V Roll No. : 28
Subject : Lab Course Based On Paper No 505 (Visual Programming)

Assignment No. 5

• Write a c# program to display “Type Casting (or) Conversion(Implicit &


Explicit casting)”and compile it with csc.exe.

a) Implicit casting (or) conversion

using System;

namespace ConsoleApp6
{
class implicitCasting
{
static void Main(string[] args)
{
int i = 56;
long l = i;
float f = l;
Console.WriteLine("int value" + i);
Console.WriteLine("float value" + f);
Console.WriteLine("long value" + l);
}
}
}

Output :

BCA III SEM V Page 8


Name :-Tanuja Prakash Date.
Class :- BCA-III Sem : V Roll No. : 28
Subject : Lab Course Based On Paper No 505 (Visual Programming)

BCA III SEM V Page 9


Name :-Tanuja Prakash Date.
Class :- BCA-III Sem : V Roll No. : 28
Subject : Lab Course Based On Paper No 505 (Visual Programming)

• Write a c# program to display “Type Casting (or) Conversion(Implicit &


Explicit casting)”and compile it with csc.exe.

b) Explicit casting (or) conversion

using System;

namespace ConsoleApp7
{
class ExplicitCasting
{
static void Main(string[] args)
{
double d = 56.65;
int i = (int)d;
Console.WriteLine("value of i is " + i);
}
}
}

Output :

BCA III SEM V Page 10


Name :-Tanuja Prakash Date.
Class :- BCA-III Sem : V Roll No. : 28
Subject : Lab Course Based On Paper No 505 (Visual Programming)

Assignment No. 6

• Write a c# program to display “Boxing & Unboxing”and compile it with


csc.exe.

a) Boxing
using System;

namespace ConsoleApp8
{
class TestBoxing
{
static void Main()
{
int i = 123;
object o = i; // boxing copies the value of i into object o.
i = 456; // Charge the values of i.
//The change in i does not affect the value stored in o.

System.Console.WriteLine("The value-type value = {0}",i);


System.Console.WriteLine("The object-type value = {0}",o);
}
}
}

Output :

BCA III SEM V Page 11


Name :-Tanuja Prakash Date.
Class :- BCA-III Sem : V Roll No. : 28
Subject : Lab Course Based On Paper No 505 (Visual Programming)

BCA III SEM V Page 12


Name :-Tanuja Prakash Date.
Class :- BCA-III Sem : V Roll No. : 28
Subject : Lab Course Based On Paper No 505 (Visual Programming)

• Write a c# program to display “Boxing & Unboxing”and compile it with


csc.exe.

b) Unboxing

using System;

namespace ConsoleApp9
{
class TestUnboxing
{
static void Main()
{
int i = 123;
object o=i; // implicit boxing
try
{
int j = (short)o;//attemt to unbox
System.Console.WriteLine("Unboxing OK.");
}
catch (System.InvalidCastException e)
{
System.Console.WriteLine("{0} Error : Incorrect unboxing.",
e.Message);
}
}
}
}

Output:

BCA III SEM V Page 13


Name :-Tanuja Prakash Date.
Class :- BCA-III Sem : V Roll No. : 28
Subject : Lab Course Based On Paper No 505 (Visual Programming)

BCA III SEM V Page 14


Name :-Tanuja Prakash Date.
Class :- BCA-III Sem : V Roll No. : 28
Subject : Lab Course Based On Paper No 505 (Visual Programming)

Assignment No. 7

• Write a c# program to display “Forget code”and compile it with csc.exe.

using System;

namespace ConsoleApp10
{
class Program
{
static void Main(string[] args)
{
string mine = "Forget code";
string referenceType1 = mine ; //Boxing
string valueType = referenceType1; //Unboxing

bool b = true;
Boolean refrenceType2 = b; //Boxing
bool vaslueType2 = refrenceType2; //Unboxing

System.Console.WriteLine(mine);
System.Console.WriteLine(referenceType1);
System.Console.WriteLine(valueType);

System.Console.WriteLine(b);
System.Console.WriteLine(refrenceType2);
System.Console.WriteLine(vaslueType2);
}
}
}
Output :

BCA III SEM V Page 15


Name :-Tanuja Prakash Date.
Class :- BCA-III Sem : V Roll No. : 28
Subject : Lab Course Based On Paper No 505 (Visual Programming)

BCA III SEM V Page 16


Name :-Tanuja Prakash Date.
Class :- BCA-III Sem : V Roll No. : 28
Subject : Lab Course Based On Paper No 505 (Visual Programming)

Assignment No. 8

• Write a c# program to display “Pass By Value”and compile it with csc.exe.


a)

using System;

namespace ConsoleApp11
{
public class PassingByValues
{
static int a = 4;
static int b = 7;

static void Swap(int a, int b)

{
int temp;
temp = a;
a = b;
b = temp;
System.Console.WriteLine("Inside Swap method");
System.Console.WriteLine("a is {0}", a);
System.Console.WriteLine("b is {0}", b);
}

static void Main()


{
System.Console.WriteLine("Befor Swapping");
System.Console.WriteLine("a is {0}",a);
System.Console.WriteLine("b is {0}",b);
}

BCA III SEM V Page 17


Name :-Tanuja Prakash Date.
Class :- BCA-III Sem : V Roll No. : 28
Subject : Lab Course Based On Paper No 505 (Visual Programming)

}
}
Output:

BCA III SEM V Page 18


Name :-Tanuja Prakash Date.
Class :- BCA-III Sem : V Roll No. : 28
Subject : Lab Course Based On Paper No 505 (Visual Programming)

b)

using System;

namespace ConsoleApp12
{
class PassByValue
{
static void Main(string[] args)
{
int x = 10;
System.Console.WriteLine("Variable Value Before Calling the Method:
{0}", x);
Multiplication(x);
System.Console.WriteLine("Variable Value After Calling the Method:
{0}", x);
System.Console.WriteLine("Press Enter Key to Exit..");
System.Console.ReadLine();
}

public static void Multiplication (int a)


{
a *= a;
System.Console.WriteLine("Variable Value Inside the Method :{0}", a);
}
}
}

Output :

BCA III SEM V Page 19


Name :-Tanuja Prakash Date.
Class :- BCA-III Sem : V Roll No. : 28
Subject : Lab Course Based On Paper No 505 (Visual Programming)

BCA III SEM V Page 20


Name :-Tanuja Prakash Date.
Class :- BCA-III Sem : V Roll No. : 28
Subject : Lab Course Based On Paper No 505 (Visual Programming)

Assignment No. 9

• Write a c# program to display “Pass By Reference”and compile it with


csc.exe.
a)

using System;

namespace ConsoleApp13
{
public class PassongByRefrence
{
static int a = 4;
static int b = 7;

static void Swap(ref int a, ref int b)


{
int temp;
temp = a;
a = b;
b = temp;

System.Console.WriteLine("Inside Swap methode");


System.Console.WriteLine("a is {0}", a);
System.Console.WriteLine("b is {0}", b);
}
static void Main()

{
System.Console.WriteLine("Before Swapping");
System.Console.WriteLine("a is {0}", a);
System.Console.WriteLine("b is {0}", b);

Swap(ref a, ref b);

BCA III SEM V Page 21


Name :-Tanuja Prakash Date.
Class :- BCA-III Sem : V Roll No. : 28
Subject : Lab Course Based On Paper No 505 (Visual Programming)

System.Console.WriteLine("After Swapping");
System.Console.WriteLine("'a is {0}", a);
System.Console.WriteLine("b is {0}", b);
}
}
}

Output:

BCA III SEM V Page 22


Name :-Tanuja Prakash Date.
Class :- BCA-III Sem : V Roll No. : 28
Subject : Lab Course Based On Paper No 505 (Visual Programming)

• Write a c# program to display “Pass By Reference”and compile it with


csc.exe.

b)

using System;

namespace ConsoleApp14
{
class PassByRef
{
static void Main(string[] args)
{
int x = 10;
System.Console.WriteLine("Variable Value Befor Calling the Method:
{0}", x);
multiplication(ref x);
System.Console.WriteLine("Variable Value After Calling the Method:
{0}", x);
System.Console.WriteLine("Press Enter Key to Exit..");
}
public static void multiplication (ref int a)
{
a *= a;
System.Console.WriteLine("Variable Value Inside the Method: {0}", a);
}
}
}
Output:

BCA III SEM V Page 23


Name :-Tanuja Prakash Date.
Class :- BCA-III Sem : V Roll No. : 28
Subject : Lab Course Based On Paper No 505 (Visual Programming)

BCA III SEM V Page 24


Name :-Tanuja Prakash Date.
Class :- BCA-III Sem : V Roll No. : 28
Subject : Lab Course Based On Paper No 505 (Visual Programming)

Assignment No. 10

• Write a c# program to display “Out Parameters”and compile it with csc.exe.


a)
using System;

namespace ConsoleApp15
{
class OutKeyword
{
static void Main()
{
int val;
setValue(out val);
System.Console.WriteLine(val);
}
static void setValue(out int i)
{
i = 12;
}
}
}

Output:

BCA III SEM V Page 25


Name :-Tanuja Prakash Date.
Class :- BCA-III Sem : V Roll No. : 28
Subject : Lab Course Based On Paper No 505 (Visual Programming)

• Write a c# program to display “Out Parameters”and compile it with csc.exe.


b)
using System;

namespace ConsoleApp16
{
class Outpara
{
static void Main(string[] args)
{
int x, y;
Multiplication(out x, out y);
System.Console.WriteLine("x value: {0}", x);
System.Console.WriteLine("y value: {0}", y);
System.Console.WriteLine("Press Enter Key to Exit..");
System.Console.ReadLine();
}
public static void Multiplication (out int a, out int b)
{
a = 10;
b = 5;
a *= a;
b *= b;
BCA III SEM V Page 26
Name :-Tanuja Prakash Date.
Class :- BCA-III Sem : V Roll No. : 28
Subject : Lab Course Based On Paper No 505 (Visual Programming)

}
}
}
Output:

BCA III SEM V Page 27


Name :-Tanuja Prakash Date.
Class :- BCA-III Sem : V Roll No. : 28
Subject : Lab Course Based On Paper No 505 (Visual Programming)

Assignment No. 11

• Write a c# program to display “Partial Class”and compile it with csc.exe.

using System;

namespace ConsoleApp17
{
public partial class user
{
private string name;
private string location;
public user(string a, string b)
{
this.name = a;
this.location = b;
}
}
public partial class user
{
public void GetUserDetails()
{
System.Console.WriteLine("Name :" + name);
System.Console.WriteLine(" Location : " + location);
}
}
class PartialClasss
{
static void Main(string[] args)
{
user u = new user("Tanuja Date", "sangli");
u.GetUserDetails();
System.Console.WriteLine("\nPress Enter Key to Exit..");
System.Console.ReadLine();
}
}

BCA III SEM V Page 28


Name :-Tanuja Prakash Date.
Class :- BCA-III Sem : V Roll No. : 28
Subject : Lab Course Based On Paper No 505 (Visual Programming)

Output:

BCA III SEM V Page 29

You might also like