Exercise Lab Sheets
Exercise Lab Sheets
// Arithmetic Operators in C#
using System;
Jagged Arrays
public class JaggedArrayTest
{
public static void Main()
{
int[][] arr = new int[2][];// Declare the array
arr[0] = new int[] { 11, 21, 56, 78 };// Initialize the array
arr[1] = new int[] { 42, 61, 37, 41, 59, 63 };
//Method Overloading
using System;
namespace MethodOverloading
{
class Program
{
static void Main(string[] args)
{
Program obj = new Program();
obj.Method(); //Invoke the 1st Method
obj.Method(10); //Invoke the 2nd Method
obj.Method("Hello"); //Invoke the 3rd Method
obj.Method(10, "Hello"); //Invoke the 4th Method
obj.Method("Hello", 10); //Invoke the 5th Method
Console.ReadKey();
}
Console.WriteLine(result);
Console.ReadKey();
}
}
using System;
namespace PropertyDemo
{
public class Employee
{
//Private Data Members
private int EId;
private string EName;
//Public Properties
public int EmpId
{
set
{
EId = value;
}
get
{
return EId;
}
}
set
{
EName = value;
}
+ get
{
Return EName;
}
}
}
class Program
{
static void Main(string[] args)
{
Employee emp= new Employee();
emp.EmpId = 1000;
emp.EmpName = "Kalpana";
Console.WriteLine("Employee Details:");
Console.WriteLine("Employee id:" + emp.EmpId);
Console.WriteLine("Employee name:" + emp.EmpName);
Console.ReadKey();
}
}
}
// Delegates demo
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Delegates_demo
{
public delegate int Mydelegate(int x,int y);
class sample
{
public static int rectangle(int a, int b)
{
return a * b;
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("My simple Delegate Program");
Mydelegate mdl = new Mydelegate(sample.rectangle);
Console.WriteLine("The Area of rectangle is {0}", mdl(4, 5));
Console.ReadKey();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace sealed_method
{
class Program
{
public class BaseClass
{
public virtual void Display()
{
Console.WriteLine("Virtual method");
}
}
public class DerivedClass : BaseClass
{
// Now the display method have been sealed and can;t be overridden
public override sealed void Display()
{
Console.WriteLine("Sealed method");
}
}
//public class ThirdClass : DerivedClass
//{
// public override void Display()
// {
// Console.WriteLine("Here we try again to override display method which is not
possible and will give error");
// }
//}
static void Main(string[] args)
{
DerivedClass ob1 = new DerivedClass();
ob1.Display();
Console.ReadLine();
}
}
}