SlideShare a Scribd company logo
.NET PRECTICALS
1
UTTRANCHAL INSTITUTE OF MANAGEMENT
PACTICAL REPORT ON
C#
DOT NET
MASTER of COMPUTER APPLICATION
SubmittedTo:- SubmittedBy:-
.NET PRECTICALS
2
Rahul singh Abhishek kr pathak
UIM, Dehradun MCA4th
SEM,
UIM,Dehradun
.NET PRECTICALS
3
List of Programs
Serial
Number
Name of the program Remark
1 Write a program to display a hello/welcome message
2 WAP for Demonstrating Data Type Conversion
3 WAP for Demonstrating String Handling
4 Given the radius of the circle, WAP to compute the area of
the circle, circumference of the circle and display their value.
5 Admission to a professional course is subject to the
following cond
Mks in maths>=80;Mks in Physics>=75;Mks in chem.>=60;
Total Mks all three>=250 or total in maths and physics>=
180
Given the details about the mks, WAP to process the
applications to list the eligible candidates.
6 WAP that will read the value of x and evaluate the following
function
Y= { 1 for x > 0; 0 for x = 0; -1 for x < 0 }
Using a) nested if statements b) else if statements and c)
conditional operators?
7 shown below is the Floyd’s triangle
1
23
456
78910
.
.
.
79………….91
WAP to print this triangle.
8 WAP to produce the following patterns
* $$$$ 1
** $$$ 22
*** $$ 333
**** $ 4444
9 WAP to generate and then sum the Fibonacci series
10 Demonstrate the typical use of the following jump
statements:
 break
 continue
.NET PRECTICALS
4
In a single program
11 WAP for Declaring Class and invokeing a method.
12 WAP to explain the concept of boxing and unboxing
13 WAP to demonstrate the addition of byte type of variables
14 WAP for using System.Collection Namespace
15 WAP for Implementing Jagged Arrays
16 Given the two one-dimensional arrays A and B which are
sorted in ascending order. WAP to merge them into a single
sorted array C that contains every items from arrays A and
B in ascending order
17 WAP for Using Reflection Class
18 WAP for Using GDI+ Classess
19 WAP for Displaying Constructors and Destructors
20 WAP to implement Single inheritance
21 WAP to implement MultiLevel inheritance
22 WAP to implement Polymorphism
23 WAP to implement Operator Overloading
24 WAP to deal with Exception Handling
25 WAP fo displaying Randomly Generated button and Click
Event
26 WAP to Demonstrate Multi Threading Example
27 WAP to implement delegates
28 WAP to implement multicast delegates
29 WAP for displaying Data Handling Application
30 WAP to use Window Form Application
31 Design and develop application as of your own choice
.NET PRECTICALS
5
1.Write a program to display a hello/welcome message
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
Console.Write("Welcome MCA in UIM");
Console.ReadKey();
}
}
}
.NET PRECTICALS
6
2. WAP for Demonstrating Data Type Conversion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
string str1 = "123.45";
Single sngl1 = Convert.ToSingle(str1);
int x = Convert.ToInt16(sngl1);
Console.WriteLine("Single 1 = {0}", sngl1);
Console.WriteLine("Integer 1 = {0}", x);
double y = Convert.ToDouble(str1);
Console.WriteLine("Double = {0}", y);
Int16 z = Convert.ToInt16(y);
Console.WriteLine("Int16 = {0}", z);
Console.ReadLine();
}
}
}
.NET PRECTICALS
7
3.. WAP for Demonstrating String Handling
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace String_Handling
{
class Program
{
static void Main(string[] args)
{
String s1 = "preeti shahi";
String s2 = s1.Insert(2, "i");
Console.WriteLine(s2);
String s3 = "preeti shahi";
Boolean b = s3.Equals(s1);
Console.WriteLine(b.ToString());
Console.WriteLine(s1.ToLower());
Console.WriteLine(s1.ToUpper());
String s4 = s1.Substring(5);
Console.WriteLine(s4);
Console.ReadKey();
}
}
}
.NET PRECTICALS
8
4 . Given the radius of the circle, WAP to compute the area of the circle, circumference
of the circle and display their value.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Circle
{
class Program
{
static void Main(string[] args)
{
const double pi = 3.14;
Console.WriteLine("Enter the radius of the circle");
double r = Convert.ToDouble(Console.ReadLine());
double area = pi * r * r;
Console.WriteLine("Area is:" + area.ToString());
double curc = 2 * pi * r;
Console.WriteLine("Circumference is:" + curc.ToString());
Console.ReadKey();
}
}
.NET PRECTICALS
9
5.Admission to a professional course is subject to the following cond
Mks in maths>=80;Mks in Physics>=75;Mks in chem.>=60; Total Mks all three>=250
or total in maths and physics>= 180
Given the details about the mks, WAP to process the applications to list the eligible
candidates.
using System;
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the marks of Maths,Physics and
Chemistry");
int Math = int.Parse(Console.ReadLine());
int Phys = int.Parse(Console.ReadLine());
int Chem = int.Parse(Console.ReadLine());
int total = Math + Phys + Chem;
int MP = Math + Phys;
if (total >= 250 || MP >= 180)
{
if (Math >= 80 && Phys >= 75 && Chem >= 60)
{
Console.WriteLine("Candidates is Eligible");
}
else
{
Console.WriteLine("Candidates is not Eligible");
}
}
else
{
Console.WriteLine("Candidates is not Eligible");
}
Console.ReadKey();
}
}
.NET PRECTICALS
10
.NET PRECTICALS
11
6.WAP that will read the value of x and evaluate the following function
Y= { 1 for x > 0; 0 for x = 0; -1 for x < 0 }
Using a) nested if statements b) else if statements and c) conditional operators?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Evaluate_x
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the value of X");
int x = int.Parse(Console.ReadLine());
int y = 0;
//Using Nested If Statement
if (x > 0)
{
y = 1;
}
else if (x == 0)
{
y = 0;
}
else if (x < 0)
{
y = -1;
}
Console.WriteLine("Using else-if Statement:" + y.ToString());
y = (x == 0) ? 0 : (x > 0) ? 1 : (x < 0) ? -1 : 0;
Console.WriteLine("Using Conditional Operation:" + y.ToString());
Console.ReadKey();
}
}
}
.NET PRECTICALS
12
.NET PRECTICALS
13
7. shown below is WAP to show the Floyd’s triangle on the basis of rows
using System;
class Program
{
static void Main(string[] args)
{
int n, i, c, a = 1;
Console.WriteLine("Enter the number of rows till you want to
print");
n = int.Parse(Console.ReadLine());
for (i = 1; i <= n; i++)
{
for (c = 1; c <= i; c++)
{
Console.Write(a.ToString());
a++;
}
Console.WriteLine();
}
Console.ReadKey();
}
}
.NET PRECTICALS
14
8. shown below is the Floyd’s triangle
1
23
456
78910
.
.
.
79………….91
WAP to print this triangle.
using System;
class Program
{
static void Main(string[] args)
{
int n, i, c, a = 1;
bool k = true;
Console.WriteLine("Enter the number till you want to print");
n = int.Parse(Console.ReadLine());
for (i = 1; i <= n; i++)
{
for (c = 1; c <= i; c++)
{
if(a==n)
{
k=false;
break;
}
Console.Write( a.ToString());
a++;
}
if (k == false)
{
break;
}
Console.WriteLine();
}
Console.ReadKey();
}
}
.NET PRECTICALS
15
.NET PRECTICALS
16
9.WAP to produce the following patterns
* $$$$ 1
** $$$ 22 .
*** $$ 333
**** $ 4444
using System;
class Program
{
static void Main(string[] args)
{
int n, c, k;
Console.WriteLine("Enter The Number Of Rows");
n = int.Parse(Console.ReadLine());
//Number Tirangle
for (c = 1; c <= n; c++)
{
for (k = 1; k <= c; k++)
{
Console.Write(c);
}
Console.WriteLine();
}
Console.WriteLine();
//Dollar Tirangle
for (c = 1; c <= n; c++)
{
for (k = 1; k <= c; k++)
{
Console.Write("$");
}
Console.WriteLine();
}
Console.WriteLine();
// Star Traingle
for (c = n; c >= 1; c--)
{
for (k = 1; k <= c; k++)
{
Console.Write("*");
}
Console.WriteLine();
}
Console.ReadKey();
}
}
.NET PRECTICALS
17
.NET PRECTICALS
18
10..WAP to generate and then sum the fibonacci series:-
using System;
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the terms in Fibonacci series:-");
int n = int.Parse(Console.ReadLine());
int a = -1, b = 1, c = 0, sum = 0;
for (int i = 1; i <= n; i++)
{
c = a + b;
sum = sum + c;
a = b;
b = c;
}
Console.WriteLine(sum.ToString());
Console.ReadKey();
}
}
.NET PRECTICALS
19
11. Demonstrate the typical use of the following jump statements:
 break
 continue
In a single program
using System;
class Program
{
static void Main(string[] args)
{
//Continue Statement
for (int i = 0; i <= 15; i++)
{
if (i == 5)
{
continue;
}
Console.Write(i.ToString() + " ");
}
Console.WriteLine();
//Break Statement
for (int i = 0; i <= 15; i++)
{
if (i == 10)
{
break;
}
Console.Write(i.ToString() + " ");
}
Console.ReadKey();
}
}
.NET PRECTICALS
20
.NET PRECTICALS
21
12.WAP for Declaring Class and invoking a method.
using System;
class Rect
{
int l, b;
public Rect(int l, int b)
{
this.l = l;
this.b = b;
}
public int getArea()
{
return l * b;
}
}
class Program
{
static void Main(string[] args)
{
Rect a = new Rect(28, 15);
Console.WriteLine("Area of rectangle is : " +
a.getArea().ToString());
Console.ReadKey();
}
}
.NET PRECTICALS
22
13.WAP to explain the concept of boxing and un boxing
using System;
class Program
{
static void Main(string[] args)
{
int i = 123;
object o = i;//Boxing
Console.WriteLine("Boxing OK");
int j = (int)o; //UnBoxing
System.Console.WriteLine("Unboxing OK");
try
{
int k = (short)o;//InvalidCastException Generated
System.Console.WriteLine("Unboxing OK");
}
catch (System.InvalidCastException e)
{
System.Console.WriteLine("Incorrect Unboxing.", e.Message);
}
Console.ReadKey();
}
}
.NET PRECTICALS
23
14.WAP to demonstrate the addition of byte type of variables:-
using System;
class Program
{
static void Main(string[] args)
{
byte b1 = 88;
byte b2 = 79;
//byte sum = b1 + b2; error cannot implicitly convert int to byte
int sum = b1 + b2; //No error
Console.WriteLine(sum.ToString());
Console.ReadKey();
}
}
.NET PRECTICALS
24
15. WAP for using System.Collection Namespace
using System;
using System.Collections;
namespace system.collection_array_list
{
class Program
{
static void Main(string[] args)
{
ArrayList n = new ArrayList();
n.Add("Preeti Shahi");
n.Add("Yamini Bisht");
n.Add("Gaurav Sharma");
n.Add("Sachin Sisodia");
n.Add("Abhishek Sharma");
n.Add("Abhishek Pathak");
Console.WriteLine("Capacity=" + n.Capacity);
Console.WriteLine("Element present=" + n.Count);
for (int i = 0; i < n.Count; i++)
{
Console.Write(n[i] + " ");
}
Console.WriteLine();
//Sorting Array List
n.Sort();
for (int i = 0; i < n.Count; i++)
{
Console.Write(n[i] + " ");
}
Console.WriteLine();
//Removing An element
n.RemoveAt(2);
for (int i = 0; i < n.Count; i++)
{
Console.Write(n[i] + " ");
}
Console.ReadKey();
}
}
}
.NET PRECTICALS
25
.NET PRECTICALS
26
16.WAP for Implementing Jagged Arrays
using System;
class Program
{
static void Main(string[] args)
{
const int rows = 3;
int[][] jagArr = new int[rows][];
jagArr[0] = new int[2];
jagArr[1] = new int[3];
jagArr[2] = new int[4];
jagArr[0][1] = 67;
jagArr[1][0] = 83;
jagArr[1][1] = 57;
jagArr[2][0] = 63;
jagArr[2][3] = 14;
for (int i = 0; i < 2; i++)
{
Console.Write(jagArr[0][i] + " ");
for (int j = 0; j < 3; j++)
{
Console.Write(jagArr[1][j] + " ");
for (int k = 0; k < 4; k++)
{
Console.Write(jagArr[2][k] + " ");
} Console.WriteLine();
}
Console.WriteLine();
}
Console.ReadKey();
}
}
.NET PRECTICALS
27
.NET PRECTICALS
28
17. Given the two one-dimensional arrays A and B which are sorted in ascending order.
WAP to merge them into a single sorted array C that contains every items from arrays A
and B in ascending order
using System;
class Program
{
static void Main(string[] args)
{
int[] a = { 10, 20, 30, 40, 50, 60, 70, 80, 90 };
int[] b = { 18, 36, 54, 72, 90, 108, 126, 144, 120 };
int[] c = new int[a.Length + b.Length];
//Mearging To New Array C
a.CopyTo(c, 0);
b.CopyTo(c, a.Length);
//Sorting Array C
for (int i = 0; i < c.Length; i++)
{
for (int j = i + 1; j < c.Length; j++)
{
if (c[i] > c[j])
{
int temp = c[i];
c[i] = c[j];
c[j] = temp;
}
}
}
for (int i = 0; i < c.Length; i++)
{
Console.WriteLine(c[i]);
}
Console.ReadKey();
}
}
.NET PRECTICALS
29
.NET PRECTICALS
30
18. WAP for Using Reflection Class
using System;
using System.Reflection;
namespace Wap_To_Reflection
{
class Program
{
static void Main(string[] args)
{
Type t = typeof(System.String);
ConstructorInfo[] ci = t.GetConstructors();
Console.WriteLine("Constructors are");
foreach (ConstructorInfo ctemp in ci)
{
Console.WriteLine(ctemp.ToString());
}
Console.WriteLine();
Console.WriteLine("Methods are");
MethodInfo[] mifo = t.GetMethods();
foreach (MethodInfo mifot in mifo)
{
Console.WriteLine(mifot.ToString());
}
Console.ReadKey();
}
}
}
.NET PRECTICALS
31
19. WAP for Using GDI+ Classes
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 WindowsFormsApplication6
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Graphics g = CreateGraphics();
Color forecolor = Color.Black;
Color backcolor = Color.White;
Font font = new Font("Algerian", 26);
g.FillRectangle(new SolidBrush(backcolor), ClientRectangle);
g.DrawString("Hello friends … m VICKY", font, new
SolidBrush(forecolor), 15, 15);
Pen myPen = new Pen(new SolidBrush(forecolor), 2);
Point p1 = new Point(40);
Point p2 = new Point(90);
g.DrawRectangle(myPen, 50, 150, 100, 50);
g.DrawEllipse(myPen, 100, 50, 80, 40);
g.FillEllipse(Brushes.Black, 100, 50, 80, 40);
}
}
}
.NET PRECTICALS
32
.NET PRECTICALS
33
20. WAP for Displaying Constructors and Destructors
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Constructor_and_Distructor
{
class Rect
{
private int l, b;
public Rect(int l, int b)
{
Console.WriteLine("Constructor Call");
this.l = l;
this.b = b;
}
public int area()
{
return l * b;
}
Rect()
{
Console.WriteLine("Destructor call");
}
}
class Program
{
static void Main(string[] args)
{
Rect r = new Rect(32, 24);
Console.WriteLine(r.area().ToString());
Console.ReadKey();
}
}
}
.NET PRECTICALS
34
.NET PRECTICALS
35
21. WAP to implement Single inheritance
using System;
class Item
{
public void x()
{
Console.WriteLine("Item Code=***");
}
}
class Fruit : Item
{
public void type()
{
Console.WriteLine("Fruit type = Mango");
}
}
class SingleInheritance
{
static void Main(string[] args)
{
Item item = new Item();
Fruit fruit = new Fruit();
item.x();
fruit.type();
Console.ReadKey();
}
}
.NET PRECTICALS
36
22. WAP to implement MultiLevel inheritance
using System;
class Student
{
public string name;
public int age;
public Student(string name, int age)
{
this.name = name;
this.age = age;
}
}
class Player : Student
{
public string sport;
public string team;
public Player(string sport, string team, string name, int age)
: base(name, age)
{
this.sport = sport;
this.team = team;
}
}
class CricketPlayer : Player
{
public int runs;
public CricketPlayer(int runs, string sport, string team, string
name, int age)
: base(sport, team, name, age)
{
this.runs = runs;
}
public void Show()
{
Console.WriteLine("Player:" + name);
Console.WriteLine("Age:" + age);
Console.WriteLine("Sport:" + sport);
Console.WriteLine("Team:" + team);
Console.WriteLine("Runs:" + runs);
}
}
class Program
{
static void Main(string[] args)
{
CricketPlayer u = new CricketPlayer(210, "Cricket", "India",
"Sachin Tendulkar", 43);
u.Show();
Console.ReadKey();
}
}
.NET PRECTICALS
37
.NET PRECTICALS
38
23. WAP to implement Polymorphism
using System;
class Fruit
{
public virtual void display()
{
Console.WriteLine("Seasonal Fruits");
}
}
class SeasonalFruit : Fruit
{
public override void display()
{
Console.WriteLine("Seasonal Fruit:Mango");
}
}
class NonSeasonalFruit : Fruit
{
public override void display()
{
Console.WriteLine("NonSeasonal Fruit:Grapes");
}
}
class InclusionPolymorphism
{
static void Main(string[] args)
{
Fruit m = new Fruit();
m = new SeasonalFruit();//Upcasting
m.display();
m = new NonSeasonalFruit();//Upcasting
m.display();
Console.ReadKey();
}
}
.NET PRECTICALS
39
.NET PRECTICALS
40
24. WAP to implement Operator Overloading
using System;
class A
{
int a, b;
public void input(int x, int y)
{
a = x;
b = y;
}
public void output()
{
Console.WriteLine(a + " " + b);
}
public static A operator +(A a1, A a2)//Binary Operator OverLoad(+)
{
A a3 = new A();
a3.a = a1.a + a2.a;
a3.b = a1.b + a2.b;
return a3;
}
}
class B
{
static void Main()
{
A a1 = new A();
A a2 = new A();
A a3 = new A();
a1.input(38, 46);
a1.output();
a2.input(40, 59);
a2.output();
a3 = a1 + a2;
a3.output();
Console.Read();
}
}
.NET PRECTICALS
41
.NET PRECTICALS
42
25. WAP to deal with Exception Handling
using System;
class A
{
static void Main()
{
try
{
int a, b, c;
Console.WriteLine("Enter a and b:");
a = int.Parse(Console.ReadLine());
b = int.Parse(Console.ReadLine());
c = a / b;
Console.WriteLine("Output is" + c);
}
catch (Exception e)
{
Console.WriteLine("Divide by zero is an error");
}
Console.Read();
}
}
.NET PRECTICALS
43
26. WAP for displaying Randomly Generated button and Click Event
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 Randomly_Generated_Button
{
public partial class RandomGenBt : Form
{
private Button b1;
private int counter1,counter2;
public RandomGenBt()
{
counter1 = 25;
counter2 = 25;
InitializeComponent();
}
private void cmdGen_Click(object sender, EventArgs e)
{
b1 = new Button();
b1.Location = new Point(counter1, counter2);
b1.Size = new Size(50, 25);
b1.Text = counter1.ToString() + " " + counter2.ToString();
b1.Click+=new EventHandler(x);
this.Controls.Add(b1);
counter1 = counter1 + 52;
counter2 = counter2 + 27;
}
private void x(object sender,EventArgs e)
{
MessageBox.Show(b1.Text.ToString());
}
}
}
.NET PRECTICALS
44
.NET PRECTICALS
45
27. WAP to Demonstrate Multi Threading Example
using System;
using System.Collections.Generic;
using System.Threading;
class Program
{
static void Main(string[] args)
{
// creating more than one thread in the application
Thread FirstThread = new Thread(FirstFunction);
Thread SecondThread = new Thread(SecondFunction);
Thread ThirdThread = new Thread(ThirdFunction);
Console.WriteLine("nThreading Starts...n");
//Starting more than one thread in the application
FirstThread.Start();
SecondThread.Start();
ThirdThread.Start();
}
public static void FirstFunction()
{
for (int number = 1; number <= 5; number++)
{
Console.WriteLine("First Thread Displays: " + number);
Thread.Sleep(200);
}
}
public static void SecondFunction()
{
for (int number = 1; number <= 5; number++)
{
Console.WriteLine("Second Thread Displays: " + number);
Thread.Sleep(500);
}
}
public static void ThirdFunction()
{
for (int number = 1; number <= 5; number++)
{
Console.WriteLine("Third Thread Displays: " + number);
Thread.Sleep(700);
}
Console.Write("nPress ENTER to quit...");
Console.ReadLine();
}
}
.NET PRECTICALS
46
.NET PRECTICALS
47
28. WAP to implement delegates
using System;
delegate void MCA();
class A
{
public void f1()
{
Console.WriteLine("f1 Method");
}
public void f2()
{
Console.WriteLine("f2 Method");
}
}
class B
{
static void Main()
{
A a1 = new A();
MCA x;
x = a1.f1;
x += a1.f2;
x();
Console.Read();
}
}
.NET PRECTICALS
48
29. WAP to implement multicast delegates
using System;
public delegate void MCA();
class Deltest
{
public void a()
{
Console.WriteLine("Single Delegate");
}
public void b()
{
Console.WriteLine("Multicast Delegate");
}
}
class Program
{
static void Main(string[] args)
{
Deltest dt = new Deltest();
MCA d = new MCA(dt.a);
d += new MCA(dt.b);
d();
Console.ReadKey();
}
}
.NET PRECTICALS
49
30. WAP for displaying Data Handling Application
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;
using System.Data.Odbc;
public partial class DataHandling : Form
{
OdbcConnection con;
OdbcDataAdapter da;
DataSet ds;
OdbcDataReader dr;
OdbcCommand cmd;
private int ID;
public DataHandling()
{
con = new OdbcConnection("DSN=Icon;");
con.Open();
da = new OdbcDataAdapter("Select * From tblItem", con);
ds = new DataSet();
da.Fill(ds);
InitializeComponent();
}
private void cmdShow_Click(object sender, EventArgs e)
{
dgItems.DataSource = ds.Tables[0];
}
private void dgItems_Click(object sender, EventArgs e)
{
txtName.Text = dgItems.CurrentRow.Cells[1].Value.ToString();
txtID.Text = dgItems.CurrentRow.Cells[2].Value.ToString();
ID = (int)dgItems.CurrentRow.Cells[0].Value;
}
private void cmdUpdate_Click(object sender, EventArgs e)
{
cmd = new OdbcCommand("Update tblItem Set Item_Name='" +
txtName.Text.ToString() + "',Item_Code='" + txtID.Text.ToString() + "' Where
Item_ID=" + ID, con);
cmd.ExecuteNonQuery();
}
}
.NET PRECTICALS
50
.NET PRECTICALS
51
31.WAP to use Window Form Application
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 windows_Form_application
{
public partial class MDIContainer : Form
{
private int counter;
public MDIContainer()
{
counter = 0;
InitializeComponent();
}
private void cmdNewForm_Click(object sender, EventArgs e)
{
NewForm nf = new NewForm();
nf.MdiParent = this;
nf.Text = "Form Number .: " + counter.ToString();
counter = counter + 1;
nf.Show();
}
private void cmdChangeColor_Click(object sender, EventArgs e)
{
CDialog.ShowDialog();
this.ActiveMdiChild.BackColor = CDialog.Color;
}
}
}
.NET PRECTICALS
52

More Related Content

PPT
Csphtp1 06
PDF
GNU octave
DOC
Java programming lab assignments
PPT
Csphtp1 08
PPT
PPTX
matlab
PPTX
Technical aptitude test 2 CSE
Csphtp1 06
GNU octave
Java programming lab assignments
Csphtp1 08
matlab
Technical aptitude test 2 CSE

What's hot (18)

PDF
Programming in C Lab
PDF
Categories for the Working C++ Programmer
PDF
Debugging and Profiling C++ Template Metaprograms
PPT
Heaps & Adaptable priority Queues
PPT
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/Theta
PPTX
Technical aptitude Test 1 CSE
ODP
Optimized declarative transformation First Eclipse QVTc results
DOCX
Java codes
PPT
Concept of c
PPTX
An Introduction to MATLAB for beginners
PDF
GTC16 - S6410 - Comparing OpenACC 2.5 and OpenMP 4.5
PPT
9781285852744 ppt ch08
DOCX
HSc Computer Science Practical Slip for Class 12
PDF
maxbox starter60 machine learning
DOC
Matlab file
PPT
9781285852744 ppt ch16
PPS
C programming session 04
PDF
Java -lec-5
Programming in C Lab
Categories for the Working C++ Programmer
Debugging and Profiling C++ Template Metaprograms
Heaps & Adaptable priority Queues
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/Theta
Technical aptitude Test 1 CSE
Optimized declarative transformation First Eclipse QVTc results
Java codes
Concept of c
An Introduction to MATLAB for beginners
GTC16 - S6410 - Comparing OpenACC 2.5 and OpenMP 4.5
9781285852744 ppt ch08
HSc Computer Science Practical Slip for Class 12
maxbox starter60 machine learning
Matlab file
9781285852744 ppt ch16
C programming session 04
Java -lec-5
Ad

Viewers also liked (20)

PPTX
Finemore
PPT
TDeX Computer, Tradex Informática.
PPSX
Firestarter Intro.Pps
PPTX
QUADRILATERALS
PDF
Globe exploration heb
PDF
Shemen
PDF
Corporate Metabolism
PDF
Harsanyi_Portfilo2001-2010
PDF
Alpha 2012
PDF
南理工2012年研究生招生简章
PDF
Biofeedback alapú interakciók
PDF
Dolgok Allasa - Veszprem 2014
PPTX
Arterylite
PPTX
PDF
Chasing Egregors
PPT
Shemen
PDF
Pengeélen
PDF
Arduino Prezi (BKF)
PPT
480 sensors
PDF
Spe prms
Finemore
TDeX Computer, Tradex Informática.
Firestarter Intro.Pps
QUADRILATERALS
Globe exploration heb
Shemen
Corporate Metabolism
Harsanyi_Portfilo2001-2010
Alpha 2012
南理工2012年研究生招生简章
Biofeedback alapú interakciók
Dolgok Allasa - Veszprem 2014
Arterylite
Chasing Egregors
Shemen
Pengeélen
Arduino Prezi (BKF)
480 sensors
Spe prms
Ad

Similar to Net practicals lab mannual (20)

DOCX
39927902 c-labmanual
DOCX
39927902 c-labmanual
DOC
Java final lab
PDF
C# Lab Programs.pdf
PDF
C# Lab Programs.pdf
PDF
Java programming lab manual
PPTX
C#.net
DOC
Cs2312 OOPS LAB MANUAL
PPTX
Lambdas puzzler - Peter Lawrey
DOCX
PDF
Java Lab Manual
PPTX
APSEC2020 Keynote
PDF
JavaProgrammingManual
PDF
Python Manuel-R2021.pdf
PDF
Review Questions for Exam 10182016 1. public class .pdf
PPT
CSE215_Module_02_Elementary_Programming.ppt
PPTX
Seminar 2 coding_principles
PDF
Data Structure Radix Sort
PPTX
Chapter i(introduction to java)
PDF
Java practical(baca sem v)
39927902 c-labmanual
39927902 c-labmanual
Java final lab
C# Lab Programs.pdf
C# Lab Programs.pdf
Java programming lab manual
C#.net
Cs2312 OOPS LAB MANUAL
Lambdas puzzler - Peter Lawrey
Java Lab Manual
APSEC2020 Keynote
JavaProgrammingManual
Python Manuel-R2021.pdf
Review Questions for Exam 10182016 1. public class .pdf
CSE215_Module_02_Elementary_Programming.ppt
Seminar 2 coding_principles
Data Structure Radix Sort
Chapter i(introduction to java)
Java practical(baca sem v)

Recently uploaded (20)

PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
Pre independence Education in Inndia.pdf
PPTX
master seminar digital applications in india
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Insiders guide to clinical Medicine.pdf
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
RMMM.pdf make it easy to upload and study
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Basic Mud Logging Guide for educational purpose
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
O5-L3 Freight Transport Ops (International) V1.pdf
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
Pre independence Education in Inndia.pdf
master seminar digital applications in india
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Insiders guide to clinical Medicine.pdf
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
RMMM.pdf make it easy to upload and study
2.FourierTransform-ShortQuestionswithAnswers.pdf
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Supply Chain Operations Speaking Notes -ICLT Program
STATICS OF THE RIGID BODIES Hibbelers.pdf
Final Presentation General Medicine 03-08-2024.pptx
Basic Mud Logging Guide for educational purpose
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
human mycosis Human fungal infections are called human mycosis..pptx
3rd Neelam Sanjeevareddy Memorial Lecture.pdf

Net practicals lab mannual

  • 1. .NET PRECTICALS 1 UTTRANCHAL INSTITUTE OF MANAGEMENT PACTICAL REPORT ON C# DOT NET MASTER of COMPUTER APPLICATION SubmittedTo:- SubmittedBy:-
  • 2. .NET PRECTICALS 2 Rahul singh Abhishek kr pathak UIM, Dehradun MCA4th SEM, UIM,Dehradun
  • 3. .NET PRECTICALS 3 List of Programs Serial Number Name of the program Remark 1 Write a program to display a hello/welcome message 2 WAP for Demonstrating Data Type Conversion 3 WAP for Demonstrating String Handling 4 Given the radius of the circle, WAP to compute the area of the circle, circumference of the circle and display their value. 5 Admission to a professional course is subject to the following cond Mks in maths>=80;Mks in Physics>=75;Mks in chem.>=60; Total Mks all three>=250 or total in maths and physics>= 180 Given the details about the mks, WAP to process the applications to list the eligible candidates. 6 WAP that will read the value of x and evaluate the following function Y= { 1 for x > 0; 0 for x = 0; -1 for x < 0 } Using a) nested if statements b) else if statements and c) conditional operators? 7 shown below is the Floyd’s triangle 1 23 456 78910 . . . 79………….91 WAP to print this triangle. 8 WAP to produce the following patterns * $$$$ 1 ** $$$ 22 *** $$ 333 **** $ 4444 9 WAP to generate and then sum the Fibonacci series 10 Demonstrate the typical use of the following jump statements:  break  continue
  • 4. .NET PRECTICALS 4 In a single program 11 WAP for Declaring Class and invokeing a method. 12 WAP to explain the concept of boxing and unboxing 13 WAP to demonstrate the addition of byte type of variables 14 WAP for using System.Collection Namespace 15 WAP for Implementing Jagged Arrays 16 Given the two one-dimensional arrays A and B which are sorted in ascending order. WAP to merge them into a single sorted array C that contains every items from arrays A and B in ascending order 17 WAP for Using Reflection Class 18 WAP for Using GDI+ Classess 19 WAP for Displaying Constructors and Destructors 20 WAP to implement Single inheritance 21 WAP to implement MultiLevel inheritance 22 WAP to implement Polymorphism 23 WAP to implement Operator Overloading 24 WAP to deal with Exception Handling 25 WAP fo displaying Randomly Generated button and Click Event 26 WAP to Demonstrate Multi Threading Example 27 WAP to implement delegates 28 WAP to implement multicast delegates 29 WAP for displaying Data Handling Application 30 WAP to use Window Form Application 31 Design and develop application as of your own choice
  • 5. .NET PRECTICALS 5 1.Write a program to display a hello/welcome message using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { Console.Write("Welcome MCA in UIM"); Console.ReadKey(); } } }
  • 6. .NET PRECTICALS 6 2. WAP for Demonstrating Data Type Conversion using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication3 { class Program { static void Main(string[] args) { string str1 = "123.45"; Single sngl1 = Convert.ToSingle(str1); int x = Convert.ToInt16(sngl1); Console.WriteLine("Single 1 = {0}", sngl1); Console.WriteLine("Integer 1 = {0}", x); double y = Convert.ToDouble(str1); Console.WriteLine("Double = {0}", y); Int16 z = Convert.ToInt16(y); Console.WriteLine("Int16 = {0}", z); Console.ReadLine(); } } }
  • 7. .NET PRECTICALS 7 3.. WAP for Demonstrating String Handling using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace String_Handling { class Program { static void Main(string[] args) { String s1 = "preeti shahi"; String s2 = s1.Insert(2, "i"); Console.WriteLine(s2); String s3 = "preeti shahi"; Boolean b = s3.Equals(s1); Console.WriteLine(b.ToString()); Console.WriteLine(s1.ToLower()); Console.WriteLine(s1.ToUpper()); String s4 = s1.Substring(5); Console.WriteLine(s4); Console.ReadKey(); } } }
  • 8. .NET PRECTICALS 8 4 . Given the radius of the circle, WAP to compute the area of the circle, circumference of the circle and display their value. using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Circle { class Program { static void Main(string[] args) { const double pi = 3.14; Console.WriteLine("Enter the radius of the circle"); double r = Convert.ToDouble(Console.ReadLine()); double area = pi * r * r; Console.WriteLine("Area is:" + area.ToString()); double curc = 2 * pi * r; Console.WriteLine("Circumference is:" + curc.ToString()); Console.ReadKey(); } }
  • 9. .NET PRECTICALS 9 5.Admission to a professional course is subject to the following cond Mks in maths>=80;Mks in Physics>=75;Mks in chem.>=60; Total Mks all three>=250 or total in maths and physics>= 180 Given the details about the mks, WAP to process the applications to list the eligible candidates. using System; class Program { static void Main(string[] args) { Console.WriteLine("Enter the marks of Maths,Physics and Chemistry"); int Math = int.Parse(Console.ReadLine()); int Phys = int.Parse(Console.ReadLine()); int Chem = int.Parse(Console.ReadLine()); int total = Math + Phys + Chem; int MP = Math + Phys; if (total >= 250 || MP >= 180) { if (Math >= 80 && Phys >= 75 && Chem >= 60) { Console.WriteLine("Candidates is Eligible"); } else { Console.WriteLine("Candidates is not Eligible"); } } else { Console.WriteLine("Candidates is not Eligible"); } Console.ReadKey(); } }
  • 11. .NET PRECTICALS 11 6.WAP that will read the value of x and evaluate the following function Y= { 1 for x > 0; 0 for x = 0; -1 for x < 0 } Using a) nested if statements b) else if statements and c) conditional operators? using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Evaluate_x { class Program { static void Main(string[] args) { Console.WriteLine("Enter the value of X"); int x = int.Parse(Console.ReadLine()); int y = 0; //Using Nested If Statement if (x > 0) { y = 1; } else if (x == 0) { y = 0; } else if (x < 0) { y = -1; } Console.WriteLine("Using else-if Statement:" + y.ToString()); y = (x == 0) ? 0 : (x > 0) ? 1 : (x < 0) ? -1 : 0; Console.WriteLine("Using Conditional Operation:" + y.ToString()); Console.ReadKey(); } } }
  • 13. .NET PRECTICALS 13 7. shown below is WAP to show the Floyd’s triangle on the basis of rows using System; class Program { static void Main(string[] args) { int n, i, c, a = 1; Console.WriteLine("Enter the number of rows till you want to print"); n = int.Parse(Console.ReadLine()); for (i = 1; i <= n; i++) { for (c = 1; c <= i; c++) { Console.Write(a.ToString()); a++; } Console.WriteLine(); } Console.ReadKey(); } }
  • 14. .NET PRECTICALS 14 8. shown below is the Floyd’s triangle 1 23 456 78910 . . . 79………….91 WAP to print this triangle. using System; class Program { static void Main(string[] args) { int n, i, c, a = 1; bool k = true; Console.WriteLine("Enter the number till you want to print"); n = int.Parse(Console.ReadLine()); for (i = 1; i <= n; i++) { for (c = 1; c <= i; c++) { if(a==n) { k=false; break; } Console.Write( a.ToString()); a++; } if (k == false) { break; } Console.WriteLine(); } Console.ReadKey(); } }
  • 16. .NET PRECTICALS 16 9.WAP to produce the following patterns * $$$$ 1 ** $$$ 22 . *** $$ 333 **** $ 4444 using System; class Program { static void Main(string[] args) { int n, c, k; Console.WriteLine("Enter The Number Of Rows"); n = int.Parse(Console.ReadLine()); //Number Tirangle for (c = 1; c <= n; c++) { for (k = 1; k <= c; k++) { Console.Write(c); } Console.WriteLine(); } Console.WriteLine(); //Dollar Tirangle for (c = 1; c <= n; c++) { for (k = 1; k <= c; k++) { Console.Write("$"); } Console.WriteLine(); } Console.WriteLine(); // Star Traingle for (c = n; c >= 1; c--) { for (k = 1; k <= c; k++) { Console.Write("*"); } Console.WriteLine(); } Console.ReadKey(); } }
  • 18. .NET PRECTICALS 18 10..WAP to generate and then sum the fibonacci series:- using System; class Program { static void Main(string[] args) { Console.WriteLine("Enter the terms in Fibonacci series:-"); int n = int.Parse(Console.ReadLine()); int a = -1, b = 1, c = 0, sum = 0; for (int i = 1; i <= n; i++) { c = a + b; sum = sum + c; a = b; b = c; } Console.WriteLine(sum.ToString()); Console.ReadKey(); } }
  • 19. .NET PRECTICALS 19 11. Demonstrate the typical use of the following jump statements:  break  continue In a single program using System; class Program { static void Main(string[] args) { //Continue Statement for (int i = 0; i <= 15; i++) { if (i == 5) { continue; } Console.Write(i.ToString() + " "); } Console.WriteLine(); //Break Statement for (int i = 0; i <= 15; i++) { if (i == 10) { break; } Console.Write(i.ToString() + " "); } Console.ReadKey(); } }
  • 21. .NET PRECTICALS 21 12.WAP for Declaring Class and invoking a method. using System; class Rect { int l, b; public Rect(int l, int b) { this.l = l; this.b = b; } public int getArea() { return l * b; } } class Program { static void Main(string[] args) { Rect a = new Rect(28, 15); Console.WriteLine("Area of rectangle is : " + a.getArea().ToString()); Console.ReadKey(); } }
  • 22. .NET PRECTICALS 22 13.WAP to explain the concept of boxing and un boxing using System; class Program { static void Main(string[] args) { int i = 123; object o = i;//Boxing Console.WriteLine("Boxing OK"); int j = (int)o; //UnBoxing System.Console.WriteLine("Unboxing OK"); try { int k = (short)o;//InvalidCastException Generated System.Console.WriteLine("Unboxing OK"); } catch (System.InvalidCastException e) { System.Console.WriteLine("Incorrect Unboxing.", e.Message); } Console.ReadKey(); } }
  • 23. .NET PRECTICALS 23 14.WAP to demonstrate the addition of byte type of variables:- using System; class Program { static void Main(string[] args) { byte b1 = 88; byte b2 = 79; //byte sum = b1 + b2; error cannot implicitly convert int to byte int sum = b1 + b2; //No error Console.WriteLine(sum.ToString()); Console.ReadKey(); } }
  • 24. .NET PRECTICALS 24 15. WAP for using System.Collection Namespace using System; using System.Collections; namespace system.collection_array_list { class Program { static void Main(string[] args) { ArrayList n = new ArrayList(); n.Add("Preeti Shahi"); n.Add("Yamini Bisht"); n.Add("Gaurav Sharma"); n.Add("Sachin Sisodia"); n.Add("Abhishek Sharma"); n.Add("Abhishek Pathak"); Console.WriteLine("Capacity=" + n.Capacity); Console.WriteLine("Element present=" + n.Count); for (int i = 0; i < n.Count; i++) { Console.Write(n[i] + " "); } Console.WriteLine(); //Sorting Array List n.Sort(); for (int i = 0; i < n.Count; i++) { Console.Write(n[i] + " "); } Console.WriteLine(); //Removing An element n.RemoveAt(2); for (int i = 0; i < n.Count; i++) { Console.Write(n[i] + " "); } Console.ReadKey(); } } }
  • 26. .NET PRECTICALS 26 16.WAP for Implementing Jagged Arrays using System; class Program { static void Main(string[] args) { const int rows = 3; int[][] jagArr = new int[rows][]; jagArr[0] = new int[2]; jagArr[1] = new int[3]; jagArr[2] = new int[4]; jagArr[0][1] = 67; jagArr[1][0] = 83; jagArr[1][1] = 57; jagArr[2][0] = 63; jagArr[2][3] = 14; for (int i = 0; i < 2; i++) { Console.Write(jagArr[0][i] + " "); for (int j = 0; j < 3; j++) { Console.Write(jagArr[1][j] + " "); for (int k = 0; k < 4; k++) { Console.Write(jagArr[2][k] + " "); } Console.WriteLine(); } Console.WriteLine(); } Console.ReadKey(); } }
  • 28. .NET PRECTICALS 28 17. Given the two one-dimensional arrays A and B which are sorted in ascending order. WAP to merge them into a single sorted array C that contains every items from arrays A and B in ascending order using System; class Program { static void Main(string[] args) { int[] a = { 10, 20, 30, 40, 50, 60, 70, 80, 90 }; int[] b = { 18, 36, 54, 72, 90, 108, 126, 144, 120 }; int[] c = new int[a.Length + b.Length]; //Mearging To New Array C a.CopyTo(c, 0); b.CopyTo(c, a.Length); //Sorting Array C for (int i = 0; i < c.Length; i++) { for (int j = i + 1; j < c.Length; j++) { if (c[i] > c[j]) { int temp = c[i]; c[i] = c[j]; c[j] = temp; } } } for (int i = 0; i < c.Length; i++) { Console.WriteLine(c[i]); } Console.ReadKey(); } }
  • 30. .NET PRECTICALS 30 18. WAP for Using Reflection Class using System; using System.Reflection; namespace Wap_To_Reflection { class Program { static void Main(string[] args) { Type t = typeof(System.String); ConstructorInfo[] ci = t.GetConstructors(); Console.WriteLine("Constructors are"); foreach (ConstructorInfo ctemp in ci) { Console.WriteLine(ctemp.ToString()); } Console.WriteLine(); Console.WriteLine("Methods are"); MethodInfo[] mifo = t.GetMethods(); foreach (MethodInfo mifot in mifo) { Console.WriteLine(mifot.ToString()); } Console.ReadKey(); } } }
  • 31. .NET PRECTICALS 31 19. WAP for Using GDI+ Classes 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 WindowsFormsApplication6 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Graphics g = CreateGraphics(); Color forecolor = Color.Black; Color backcolor = Color.White; Font font = new Font("Algerian", 26); g.FillRectangle(new SolidBrush(backcolor), ClientRectangle); g.DrawString("Hello friends … m VICKY", font, new SolidBrush(forecolor), 15, 15); Pen myPen = new Pen(new SolidBrush(forecolor), 2); Point p1 = new Point(40); Point p2 = new Point(90); g.DrawRectangle(myPen, 50, 150, 100, 50); g.DrawEllipse(myPen, 100, 50, 80, 40); g.FillEllipse(Brushes.Black, 100, 50, 80, 40); } } }
  • 33. .NET PRECTICALS 33 20. WAP for Displaying Constructors and Destructors using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Constructor_and_Distructor { class Rect { private int l, b; public Rect(int l, int b) { Console.WriteLine("Constructor Call"); this.l = l; this.b = b; } public int area() { return l * b; } Rect() { Console.WriteLine("Destructor call"); } } class Program { static void Main(string[] args) { Rect r = new Rect(32, 24); Console.WriteLine(r.area().ToString()); Console.ReadKey(); } } }
  • 35. .NET PRECTICALS 35 21. WAP to implement Single inheritance using System; class Item { public void x() { Console.WriteLine("Item Code=***"); } } class Fruit : Item { public void type() { Console.WriteLine("Fruit type = Mango"); } } class SingleInheritance { static void Main(string[] args) { Item item = new Item(); Fruit fruit = new Fruit(); item.x(); fruit.type(); Console.ReadKey(); } }
  • 36. .NET PRECTICALS 36 22. WAP to implement MultiLevel inheritance using System; class Student { public string name; public int age; public Student(string name, int age) { this.name = name; this.age = age; } } class Player : Student { public string sport; public string team; public Player(string sport, string team, string name, int age) : base(name, age) { this.sport = sport; this.team = team; } } class CricketPlayer : Player { public int runs; public CricketPlayer(int runs, string sport, string team, string name, int age) : base(sport, team, name, age) { this.runs = runs; } public void Show() { Console.WriteLine("Player:" + name); Console.WriteLine("Age:" + age); Console.WriteLine("Sport:" + sport); Console.WriteLine("Team:" + team); Console.WriteLine("Runs:" + runs); } } class Program { static void Main(string[] args) { CricketPlayer u = new CricketPlayer(210, "Cricket", "India", "Sachin Tendulkar", 43); u.Show(); Console.ReadKey(); } }
  • 38. .NET PRECTICALS 38 23. WAP to implement Polymorphism using System; class Fruit { public virtual void display() { Console.WriteLine("Seasonal Fruits"); } } class SeasonalFruit : Fruit { public override void display() { Console.WriteLine("Seasonal Fruit:Mango"); } } class NonSeasonalFruit : Fruit { public override void display() { Console.WriteLine("NonSeasonal Fruit:Grapes"); } } class InclusionPolymorphism { static void Main(string[] args) { Fruit m = new Fruit(); m = new SeasonalFruit();//Upcasting m.display(); m = new NonSeasonalFruit();//Upcasting m.display(); Console.ReadKey(); } }
  • 40. .NET PRECTICALS 40 24. WAP to implement Operator Overloading using System; class A { int a, b; public void input(int x, int y) { a = x; b = y; } public void output() { Console.WriteLine(a + " " + b); } public static A operator +(A a1, A a2)//Binary Operator OverLoad(+) { A a3 = new A(); a3.a = a1.a + a2.a; a3.b = a1.b + a2.b; return a3; } } class B { static void Main() { A a1 = new A(); A a2 = new A(); A a3 = new A(); a1.input(38, 46); a1.output(); a2.input(40, 59); a2.output(); a3 = a1 + a2; a3.output(); Console.Read(); } }
  • 42. .NET PRECTICALS 42 25. WAP to deal with Exception Handling using System; class A { static void Main() { try { int a, b, c; Console.WriteLine("Enter a and b:"); a = int.Parse(Console.ReadLine()); b = int.Parse(Console.ReadLine()); c = a / b; Console.WriteLine("Output is" + c); } catch (Exception e) { Console.WriteLine("Divide by zero is an error"); } Console.Read(); } }
  • 43. .NET PRECTICALS 43 26. WAP for displaying Randomly Generated button and Click Event 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 Randomly_Generated_Button { public partial class RandomGenBt : Form { private Button b1; private int counter1,counter2; public RandomGenBt() { counter1 = 25; counter2 = 25; InitializeComponent(); } private void cmdGen_Click(object sender, EventArgs e) { b1 = new Button(); b1.Location = new Point(counter1, counter2); b1.Size = new Size(50, 25); b1.Text = counter1.ToString() + " " + counter2.ToString(); b1.Click+=new EventHandler(x); this.Controls.Add(b1); counter1 = counter1 + 52; counter2 = counter2 + 27; } private void x(object sender,EventArgs e) { MessageBox.Show(b1.Text.ToString()); } } }
  • 45. .NET PRECTICALS 45 27. WAP to Demonstrate Multi Threading Example using System; using System.Collections.Generic; using System.Threading; class Program { static void Main(string[] args) { // creating more than one thread in the application Thread FirstThread = new Thread(FirstFunction); Thread SecondThread = new Thread(SecondFunction); Thread ThirdThread = new Thread(ThirdFunction); Console.WriteLine("nThreading Starts...n"); //Starting more than one thread in the application FirstThread.Start(); SecondThread.Start(); ThirdThread.Start(); } public static void FirstFunction() { for (int number = 1; number <= 5; number++) { Console.WriteLine("First Thread Displays: " + number); Thread.Sleep(200); } } public static void SecondFunction() { for (int number = 1; number <= 5; number++) { Console.WriteLine("Second Thread Displays: " + number); Thread.Sleep(500); } } public static void ThirdFunction() { for (int number = 1; number <= 5; number++) { Console.WriteLine("Third Thread Displays: " + number); Thread.Sleep(700); } Console.Write("nPress ENTER to quit..."); Console.ReadLine(); } }
  • 47. .NET PRECTICALS 47 28. WAP to implement delegates using System; delegate void MCA(); class A { public void f1() { Console.WriteLine("f1 Method"); } public void f2() { Console.WriteLine("f2 Method"); } } class B { static void Main() { A a1 = new A(); MCA x; x = a1.f1; x += a1.f2; x(); Console.Read(); } }
  • 48. .NET PRECTICALS 48 29. WAP to implement multicast delegates using System; public delegate void MCA(); class Deltest { public void a() { Console.WriteLine("Single Delegate"); } public void b() { Console.WriteLine("Multicast Delegate"); } } class Program { static void Main(string[] args) { Deltest dt = new Deltest(); MCA d = new MCA(dt.a); d += new MCA(dt.b); d(); Console.ReadKey(); } }
  • 49. .NET PRECTICALS 49 30. WAP for displaying Data Handling Application 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; using System.Data.Odbc; public partial class DataHandling : Form { OdbcConnection con; OdbcDataAdapter da; DataSet ds; OdbcDataReader dr; OdbcCommand cmd; private int ID; public DataHandling() { con = new OdbcConnection("DSN=Icon;"); con.Open(); da = new OdbcDataAdapter("Select * From tblItem", con); ds = new DataSet(); da.Fill(ds); InitializeComponent(); } private void cmdShow_Click(object sender, EventArgs e) { dgItems.DataSource = ds.Tables[0]; } private void dgItems_Click(object sender, EventArgs e) { txtName.Text = dgItems.CurrentRow.Cells[1].Value.ToString(); txtID.Text = dgItems.CurrentRow.Cells[2].Value.ToString(); ID = (int)dgItems.CurrentRow.Cells[0].Value; } private void cmdUpdate_Click(object sender, EventArgs e) { cmd = new OdbcCommand("Update tblItem Set Item_Name='" + txtName.Text.ToString() + "',Item_Code='" + txtID.Text.ToString() + "' Where Item_ID=" + ID, con); cmd.ExecuteNonQuery(); } }
  • 51. .NET PRECTICALS 51 31.WAP to use Window Form Application 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 windows_Form_application { public partial class MDIContainer : Form { private int counter; public MDIContainer() { counter = 0; InitializeComponent(); } private void cmdNewForm_Click(object sender, EventArgs e) { NewForm nf = new NewForm(); nf.MdiParent = this; nf.Text = "Form Number .: " + counter.ToString(); counter = counter + 1; nf.Show(); } private void cmdChangeColor_Click(object sender, EventArgs e) { CDialog.ShowDialog(); this.ActiveMdiChild.BackColor = CDialog.Color; } } }