1. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
Lab List - 3 : EX.NO-1 CONSTRUCTOR
SOURCE CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace constructorbook
{
class rectangle
{
public int length, width;
public rectangle(int x, int y)
{
length = x;
width = y;
}
public int rectarea()
{
return (length * width);
}
}
class rectanglearea
{
static void Main(string[] args)
{
rectangle rect1 = new rectangle(15, 10);
int area1 = rect1.rectarea();
Console.WriteLine("area1 is" + area1);
Console.ReadLine();
}
}
}
2. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
OUTPUT:
3. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
Lab List - 3 : EX.NO-1(B) CONSTRUCTOROVERLOADING
SOURCE CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace copyconstructor
{
class sample
{
public string param1, param2;
public sample()
{
param1 = "welcome";
param2 = "c# constuctor";
}
public sample(string x, string y)
{
param1 = x;
param2 = y;
}
}
class Program
{
static void Main(string[] args)
{
int ch;
do
{
sample obj = new sample();
sample obj1 = new sample("welcome", "c#");
Console.WriteLine(obj.param1);
Console.WriteLine(obj.param2);
Console.WriteLine(obj1.param1);
Console.WriteLine(obj1.param2);
4. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
Console.WriteLine("do u want to continue");
ch = int.Parse(Console.ReadLine());
Console.ReadLine();
}
while (ch == 1);
}
}
}
OUTPUT:
5. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
Lab List - 3 : EX.NO-2 (A) SINGLE INHERITANCE
SOURCE CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace thirdlablist3
{
class shape
{
public int width;
public int height;
public void display()
{
Console.WriteLine("width and height are" + width + "and" + height);
}
}
class triangle : shape
{
public int area()
{
return width * height / 2;
}
}
class Program
{
static void Main(string[] args)
{
int ch;
do{
triangle t1=new triangle();
t1.width=4;
t1.height=4;
Console.WriteLine("area is"+t1.area());
Console.WriteLine("do u want to continue");
7. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
LAB LIST - 3 : EX.NO-4 (B) HIARECHICAL INHERITANCE
SOURCECODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class principal
{
public void monitor()
{
Console.WriteLine("monitor");
}
}
class teacher:principal
{
public void teach()
{
Console.WriteLine("teach");
}
}
class student : principal
{
public void learn()
{
Console.WriteLine("learn");
}
}
class Program
{
static void Main(string[] args)
{
int ch;
do{
principal g=new principal();
g.monitor();
8. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
teacher d=new teacher();
d.monitor();
d.teach();
student s=new student();
s.monitor();
s.learn();
Console.WriteLine("do u want to continue");
ch=int.Parse(Console.ReadLine());
Console.ReadLine();
}
while(ch==1);
}
}
}
OUTPUT:
9. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
LAB LIST - 3 : EX.NO-4 (C) MULTIPLE INHERITANCE
SOURCE CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication38
{
class shape
{
public void setwidth(int w)
{
width = w;
}
public void setheight(int h)
{
height = h;
}
protected int width;
protected int height;
}
public interface paintcost
{
int getcost(int area);
}
class rectangle : shape, paintcost
{
public int getarea()
{
return (width * height);
}
public int getcost(int area)
{
return area * 70;
}
}
class rectangletester
{
10. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
static void Main(string[] args)
{
rectangle rect = new rectangle();
int area;
rect.setwidth(5);
rect.setheight(7);
area = rect.getarea();
Console.WriteLine("total area:{0}", rect.getarea());
Console.WriteLine("total paintcost:{0}", rect.getcost(area));
Console.ReadLine();
}
}
}
OUTPUT:
11. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
LAB LIST - 3 : EX.NO-3(A) POLYMORPHISM OVERRRIDING
SOURCE CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication5
{
class baseclass
{
public virtual string yourcity()
{
return "new york";
}
}
class derivedclass : baseclass
{
public override string yourcity()
{
return "london";
}
}
class Program
{
static void Main(string[] args)
{
int ch;
do
{
derivedclass obj= new derivedclass();
string city = obj.yourcity();
Console.WriteLine(city);
Console.WriteLine("do u want to continue");
ch = int.Parse(Console.ReadLine());
Console.ReadLine();
}
while (ch == 1);
}
12. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
}
}
OUTPUT:
13. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
LAB LIST - 3 : EX.NO-3(B) POLYMORPHISM OVERLOADING
SOURCE CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication4
{
class old
{
public void add(string a1, string a2)
{
Console.WriteLine("adding two string:" + a1 + a2);
}
public void add(int a1, int a2)
{
Console.WriteLine("adding two integer:" + a1 + a2);
}
}
class Program
{
static void Main(string[] args)
{
int ch;
do
{
old obj = new old();
obj.add("eswari", "kala");
obj.add(5, 10);
Console.WriteLine("do u want to continue");
ch = int.Parse(Console.ReadLine());
Console.ReadLine();
}
while (ch == 1);
}
}
}
14. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
OUTPUT:
15. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
Lab List - 3 : EX.NO-3 (C) VIRTUAL METHOD
SOURCE CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class principal
{
public void monitor()
{
Console.WriteLine("monitor");
}
}
class teacher:principal
{
public void teach()
{
Console.WriteLine("teach");
}
}
class student : principal
{
public void learn()
{
Console.WriteLine("learn");
}
}
class Program
{
static void Main(string[] args)
{
int ch;
do{
principal g=new principal();
g.monitor();
16. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
teacher d=new teacher();
d.monitor();
d.teach();
student s=new student();
s.monitor();
s.learn();
Console.WriteLine("do u want to continue");
ch=int.Parse(Console.ReadLine());
Console.ReadLine();
}
while(ch==1);
}
}
}
OUTPUT:
17. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
Lab List - 3 : EX.NO-4 SINGLE DELEGATE
SOURCE CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace delegate1
{
class Program
{
delegate int add(int a, int b, int c);
delegate int sub(int a,int b);
static add ad=sum;
static sub sb=subt;
static void Main(string[] args)
{
int sum1,sub1;
sum1=ad.Invoke(3,4,5);
sub1=sb.Invoke(100,200);
Console.WriteLine("the sum is:"+sum1);
Console.WriteLine("the sub is:"+sub1);
Console.ReadLine();
}
static int sum(int a,int b,int c)
{
return(a+b+c);
}
static int subt(int a,int b)
{
return(a-b);
}
}
}
18. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
OUTPUT:
19. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
LAB LIST - 3 : EX.NO-4(B) MULTICAST DELEGATE
SOURCE CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace delegate2
{
delegate void dele(int a,int b);
public class oper
{
public static void add(int a, int b)
{
Console.WriteLine("{0}+{1}={2}", a, b, a + b);
}
public static void sub(int a, int b)
{
Console.WriteLine("{0}-{1}={2}", a, b, a - b);
}
}
class Program
{
static void Main(string[] args)
{
dele del = new dele(oper.add);
del += new dele(oper.sub);
del(4, 2);
del -= new dele(oper.sub);
del(1, 9);
Console.ReadLine();
}
}
}
20. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
OUTPUT:
21. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
LAB LIST - 3 : EX.NO-5(A) ERROR AND EXCEPTION HANDLING
SOURCE CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace exception
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("EXCEPTION HANDLING");
Console.WriteLine("1.Array index out of bound exceptionn 2.arithmetic
exception n3.number format exceptionn4.array size exception");
Console.WriteLine("Enter the your choice");
int c = int.Parse(Console.ReadLine());
switch (c)
{
case 1:
Console.WriteLine("Array Index Out Of Bounds exception");
try
{
int[] a = new int[3];
int b = 5;
Console.WriteLine("enter the size");
int s = int.Parse(Console.ReadLine());
Console.WriteLine("enter the numbers");
for (int i = 0; i <= s; i++)
{
a[i] = int.Parse(Console.ReadLine());
} int x = a[2] / (b - a[1]);
}
catch (IndexOutOfRangeException e)
{
Console.WriteLine("array indexerror");
}
break;
22. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
case 2:
Console.WriteLine("arithmetic exception");
try
{
int p = int.Parse(Console.ReadLine());
int q = int.Parse(Console.ReadLine());
int r = p / q;
Console.WriteLine(r);
}
catch (ArithmeticException e)
{
Console.WriteLine("division by zero");
}
break;
case 3:
Console.WriteLine("number for exception");
try
{
int k = int.Parse(Console.ReadLine());
int[] h = new int[k];
Console.WriteLine("ente the float numbers:");
for (int m = 0; m <= k; m++)
{
h[m] = int.Parse(Console.ReadLine());
} }
catch (FormatException e)
{
Console.WriteLine("type mismatch exception");
}
break;
case 4:
Console.WriteLine("Type mismatch exception");
try
{
Console.WriteLine("enter the no to enter");
int x = int.Parse(Console.ReadLine());
double[] y = new double[x];
}
catch (OverflowException e)
{
23. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
Console.WriteLine("array type mismatch");
}
break;
case 5:
Console.WriteLine("stack over flow exception");
try
{
int[] a = new int[3];
for (int i = 0; i < 5; i++)
{
a[i] = int.Parse(Console.ReadLine());
}
}
catch (StackOverflowException e)
{
Console.WriteLine("stack overflow exception");
}
break;
}
Console.ReadLine();
}
}
}
24. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
OUTPUT:
25. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
(B)INDEX OUT OF RANGE
SOURCE CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace exception3
{
class arrayoutofindex
{
public void caldiff()
{
int difference = 0;
int[] number = new int[5] { 1, 2, 3, 4, 5 };
try
{
for (int init = 1; init <= 5; init++)
{
difference = difference - number[init];
}
Console.WriteLine("the difference of the array is:" + difference);
}
catch (IndexOutOfRangeException e)
{
Console.WriteLine(e.Message);
}
}
}
class Program
{
static void Main(string[] args)
{
arrayoutofindex obj= new arrayoutofindex();
obj.caldiff();
Console.ReadLine();
}
}
}
26. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
OUTPUT:
27. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
(C)INNER EXCEPTION
SOURCE CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace exception4
{
public class myappexception : ApplicationException
{
public myappexception(string message): base(message)
{
}
public myappexception(string message, Exception inner)
{
}
}
public class exceptionexample
{
public void throwineer()
{
throw new myappexception("exception example inner exception");
}
public void catchinner()
{
try
{
this.throwineer();
}
catch (Exception e)
{
throw new myappexception("error caused by trying throwinner", e);
}
}
}
class Program
{
static void Main(string[] args)
{
28. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
exceptionexample test = new exceptionexample();
try
{
test.catchinner();
}
catch (Exception e)
{
Console.WriteLine("in main catch block.caught:{0}", e.Message);
Console.WriteLine("inner exception is{0}", e.InnerException);
}
Console.ReadLine();
}
}
}
OUTPUT:
29. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
(D)ARRAY TYPE MISMATCH EXCEPTION
SOURCE CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace keyoutexc
{
class Program
{
static void Main(string[] args)
{
try
{
//
// Create new Dictionary with string key of "one"
//
Dictionary<string, string> test = new Dictionary<string, string>();
test.Add("one", "value");
//
// Try to access key of "two"
//
string value = test["two"];
}
catch (Exception ex)
{
//
// An exception will be thrown.
//
Console.WriteLine(ex);
Console.ReadLine();
}
}
}
}
30. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
OUTPUT:
31. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
(E)KEY OUT OF EXCEPTION
SOURCE CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace keyoutexc
{
class Program
{
static void Main(string[] args)
{
try
{
//
// Create new Dictionary with string key of "one"
//
Dictionary<string, string> test = new Dictionary<string, string>();
test.Add("one", "value");
//
// Try to access key of "two"
//
string value = test["two"];
}
catch (Exception ex)
{
//
// An exception will be thrown.
//
Console.WriteLine(ex);
Console.ReadLine();
}
}
}
}
32. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
OUTPUT:
33. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
LAB LIST - 3 : EX.NO-6 MAIN THREAD
SOURCE CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace mythread
{
class Program
{
static void Main(string[] args)
{
Thread th = Thread.CurrentThread;
th.Name = "mainthread";
Console.WriteLine(" this is {0}", th.Name);
Console.ReadLine();
}
}
}
OUTPUT:
34. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
(B)TIMER THREAD
SOURCE CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace timerthread
{
class Program
{
static void Main(string[] args)
{
System.Threading.Timer thrdtimer = new Timer(run, 3, 0, 1000);
Thread.Sleep(1000);
Console.WriteLine("goodbye!! i am main thread");
Console.ReadLine();
}
static void run(object args)
{
int j = (int)args;
Console.WriteLine("hi i am executing by timer you passed" + j);
}
}}
OUTPUT:
35. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
(C)STARTING THREAD WITH CHILD THREAD
SOURCE CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace threadstartdelegate
{
class Program
{
static void Main(string[] args)
{
{
// Create Thread class object and paas object of ThreadStart delegate with
specified method its constructor
Thread th=new Thread(new ThreadStart(MyMethod));
th.Name="Child thread";
// Start child thread
th.Start();
for (int i=0; i<20; i++)
{
Console.WriteLine("Main Thread");
}
Console.WriteLine("End Thread...");
Console.ReadKey();
}
}
// Method used in thread execution
public static void MyMethod()
{
for (int i=0; i<10; i++)
{
Console.WriteLine("Child Thread");
}
}
}
}
36. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
OUTPUT:
37. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
(D)THREAD STARTED
SOURCE CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace threading
{
class program
{
static void Main(string[] args)
{ //Creating thread object to strat it
Thread th= new Thread(ThreadB);
Console.WriteLine("Threads started :");
// Start thread B
th.Start();
//Thread A executes 10 times
for (int i=0; i<10; i++)
{ Console.WriteLine("Thread : A") }
Console.WriteLine("Threads completed");
Console.ReadKey(); }
public static void ThreadB()
{ //Executes thread B 10 times
for(int i=0;i<10;i++)
{
Console.WriteLine("Thread : B"); } } } }
OUTPUT:
38. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
LAB LIST - 3 : EX.NO-7 STRUCTURES
SOURCE CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace structures
{
class Program
{
struct stu
{
public string name;
public int rollno;
public int mark1;
public int mark2;
public int mark3;
public int mark4;
public int mark5;
public int total;
public float avg;
};
public class testStructure
{ public static void Main(string[] args)
{ stu s1;
/* book1 specification */
s1.name = Console.ReadLine();
s1.rollno = int.Parse(Console.ReadLine());
s1.mark1 = int.Parse(Console.ReadLine());
s1.mark2 = int.Parse(Console.ReadLine());
s1.mark3 = int.Parse(Console.ReadLine());
s1.mark4 = int.Parse(Console.ReadLine());
s1.mark5 = int.Parse(Console.ReadLine());
s1.total = s1.mark1 + s1.mark2 + s1.mark3 + s1.mark4 + s1.mark5;
s1.avg = s1.total / 5;
Console.WriteLine("Total Marks:" + s1.total);
Console.WriteLine("Total average is:" + s1.avg);
Console.ReadLine();
} } } }
39. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
OUTPUT:
40. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
(B)ENUMERATION
SOURCE CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication42
{
class enumprogram
{
enum days { sun, mon, tue, wed, thu, fri, sat };
static void Main(string[] args)
{
int weekdaystart = (int)days.mon;
int weekdayend = (int)days.fri;
Console.WriteLine("monday:{0}", weekdaystart);
Console.WriteLine("friday:{0}", weekdayend);
Console.ReadLine();
}
}
}
OUTPUT:
41. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
LAB LIST - 3 : EX.NO-8 JAGGED ARRAY
SOURCE CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication39
{
class myarray
{
static void Main(string[] args)
{
int[][] a = new int[][] { new int[] { 0, 0 }, new int[] { 1, 2 }, new int[] { 2, 4
}, new int[] { 3, 6 }, new int[] { 4, 8 } };
int i, j;
for (i = 0; i < 5; i++)
{
for (j = 0; j < 2; j++)
{ Console.WriteLine("a[{0}][{1}]={2}", i, j, a[i][j]);
} }
Console.ReadLine(); } } }
OUTPUT:
42. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
LAB LIST - 3 : EX.NO-9 ABSTRACT
SOURCE CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace abstractprogram
{
class Program
{
abstract class ShapesClass
{
abstractpublic int Area();
}
class Square : ShapesClass
{
int side = 0;
public Square(int n)
{
side = n;
}
// Area method is required to avoid
// a compile-time error.
public override int Area()
{
return side * side;
}
static void Main(string[] args)
{
Square sq = new Square(12);
Console.WriteLine("Area of the square = {0}", sq.Area());
Console.ReadLine();
}
interface I
{
void M();
}
43. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
abstract class C : I
{
public abstract void M();
}
}
}
}
OUTPUT:
44. SUB NAME: .NET PROGRAMMING
Dr.M.KarthikaITDepartment
LAB LIST:3 EXNO-10 STUDENT MARKSTATEMENT
DESIGN:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace thirdlablist
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}