0% found this document useful (0 votes)
82 views

Dot Net Programs

The document contains 13 programs demonstrating basic C# concepts like printing output, taking user input, using different data types, arithmetic operators, assignment operators, comparison operators, loops, etc. Each program is accompanied by its expected output. The programs help learn and practice common C# programming constructs.

Uploaded by

Aman Padhy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
82 views

Dot Net Programs

The document contains 13 programs demonstrating basic C# concepts like printing output, taking user input, using different data types, arithmetic operators, assignment operators, comparison operators, loops, etc. Each program is accompanied by its expected output. The programs help learn and practice common C# programming constructs.

Uploaded by

Aman Padhy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 44

DOT NET PROGRAMS

Program:-1
Program to print a welcome message.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication9
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("welcome to c#");
Console.ReadKey();
}
}
}

Output:

welcome to c#
Program:-2
2. Program to print a name.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication9
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter your name:");
string name = Console.ReadLine();
Console.WriteLine("welcome " + name);
Console.ReadKey();
}
}
}

Output:

Enter your name:


lavanya
welcome lavanya
Program:-3

3. Program to print a message.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication9
{
class Program
{
static void Main(string[] args)
{
string message = "Hello world....!!";
Console.WriteLine(message);
Console.ReadKey();
}
}
}

Output:

Hello world....!!
Program:-4
4. Program to print data types.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication9
{
class Program
{
static void Main(string[] args)
{
string Stringvar = "hello";
int intvar = 100;
float floatvar = 10.25f;
char chatvar = 'A';
bool boolvar = true;
Console.WriteLine(Stringvar);
Console.WriteLine(intvar);
Console.WriteLine(floatvar);
Console.WriteLine(chatvar);
Console.WriteLine(boolvar);
Console.ReadKey();
}
}
}

Output:

hello
100
10.25
A
True
Program:-5
5. program for arithmetic operators.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("enter a value");
Console.WriteLine("enter b value");
int a = Convert.ToInt32(Console.ReadLine());
int b = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("the sum is :" + (a + b));
Console.WriteLine("the sub is :" + (a - b));
Console.WriteLine("the mul is :" + (a * b));
Console.WriteLine("the div is :" + (a / b));
Console.WriteLine("the mod is :" + (a % b));
Console.Read();
}
}
}

Output:

enter a value
enter b value
10
20
the sum is :30
the sub is :-10
the mul is :200
the div is :0
the mod is :10
Program:- 6
6. program for Assignment operator.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
class Assignment_operators
{
public static void Main(string []args)
{
Console.WriteLine("enter two numbers :");
int a = Convert.ToInt32(Console.ReadLine());
int b = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("sum is" + (a += b));
Console.WriteLine("sub is" + (a -= b));
Console.WriteLine("mul is" + (a *= b));
Console.WriteLine("div is" + (a /= b));
Console.WriteLine("mod is" + (a %= b));
Console.Read();
}
} }

Output:

enter a value
enter b value
10
5
the sum is :15
the sub is :5
the mul is :50
the div is :2
the mod is :0
Program:-7
7. Program for Increment operator.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication9
{
class Program
{
static void Main(string[] args)
{
int i = 0;
i++;
Console.WriteLine("The value of i is {0}", i);
Console.ReadKey();
}
}
}

Output:

The value of i is 1
Program:-8
8. Program to perform Decrement operator.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication9
{
class Program
{
static void Main(string[] args)
{
int i = 5;
Console.WriteLine("The value of i is {0}", i);
i--;
Console.WriteLine("\n now the value of i is {0}", i);
Console.ReadKey();
}
}
}

Output:

The value of i is 5

now the value of i is 4


Program:-9
9.Program to perform Comparison operator.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
class comparision_operator
{
public static void Main(string [] args)
{
Console.WriteLine("enter two numbers :");
int a = Convert.ToInt32(Console.ReadLine());
int b = Convert.ToInt32(Console.ReadLine());
if (a > b)
{
Console.WriteLine("a is greater than b" + a , +b);
}
else if (b > a)
{
Console.WriteLine("b is greater than a" + b, +a);
}
else
{
Console.WriteLine("a is equal to b" + a, +b);
}
Console.Read();
}
}
}

Output:

enter two numbers :


20
30
b is greater than a30
Program:-10
10. program to perform Or operator.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
class ORoperator
{
public static void Main(string[] args)
{
string username, userpassword;
label:
Console.WriteLine("\n\n enter your login name :\t");
username = Console.ReadLine();
Console.Write("enter your password:\t");
userpassword = Console.ReadLine();
try
{
if ((username == "lav" || username == "ambu") &&
(userpassword == "lav2307"))
{
Console.WriteLine("\n login successfull");
}
else
{
Console.WriteLine("\n unauthorised
access......aborting...!!");
}
Console.WriteLine("\n\n press y or Y for
continue....press N or n for exit....:\t");
char ans = Convert.ToChar(Console.ReadLine());
if (ans == 'Y' || ans == 'y')
{
goto label;
}
else
{
Console.WriteLine("\n press enter fpr
aborting....");
Console.ReadLine();
return;
}
}
catch { }
}
}
}

Output:

enter your login name :


lav
enter your password: lav2307

login successfull

press y or Y for continue....press N or n for exit....:


Program:-11
11. Program to perform bitwise operator.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication9
{
class Program
{
static void Main(string[] args)
{
int a = 60;
int b = 13;
int c = 0;

c = a & b;
Console.WriteLine("Line 1 - Value of c is {0}", c);

c = a | b;
Console.WriteLine("Line 2 - Value of c is {0}", c);

c = a ^ b;
Console.WriteLine("Line 3 - Value of c is {0}", c);

c = ~a;
Console.WriteLine("Line 4 - Value of c is {0}", c);

c = a << 2;
Console.WriteLine("Line 5 - Value of c is {0}", c);

c = a >> 2;
Console.WriteLine("Line 6 - Value of c is {0}", c);
Console.ReadLine();
}
}
}
Output:

Line 1 - Value of c is 12
Line 2 - Value of c is 61
Line 3 - Value of c is 49
Line 4 - Value of c is -61
Line 5 - Value of c is 240
Line 6 - Value of c is 15
Program:-12
12. Program to perform For loop.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication4
{
class for_loop
{
static void Main(string[] args)
{
int i;
for (i = 0; i < 5; i++)
{
Console.WriteLine("hiii...!!");
}
Console.Read();
}
}
}

Output:

hiii...!!
hiii...!!
hiii...!!
hiii...!!
hiii...!!
Program:-13
13. Program to perform While loop.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication4
{
class @while
{
static void Main(string[] args)
{
Console.WriteLine("enter number");
int num1 = Convert.ToInt32(Console.ReadLine());
int num2 = Convert.ToInt32(Console.ReadLine());
int i = 1;
while(i<=10)
{
int res = num1 *1;
Console.WriteLine("{0}*{1}={2}",num1,i,res);
i++;
}Console.ReadLine();
}
}
}

Output:

enter number
5
1
5*1=5
5*2=5
5*3=5
5*4=5
5*5=5
5*6=5
5*7=5
5*8=5
5*9=5
5*10=5
Program:-14
14. Program to perform Do while loop.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication4
{
class do_while
{
static void Main(string[] args)
{
int table, i, res;
table = 12;
i = 1;
do
{
res = table * i;
Console.WriteLine("{0}*{1}={2}", table, i, res);
i++;
}
while (i <= 10);
Console.Read();
}

}
}

Output:

12*1=12
12*2=24
12*3=36
12*4=48
12*5=60
12*6=72
12*7=84
12*8=96
12*9=108
12*10=120
Program:-15
15. Program to perform Switch operation.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication4
{
class @switch
{
public static void Main(string []args)
{
int num1, num2, result, option;
Console.WriteLine("please enter firstnumber and second
number");
num1 = Convert.ToInt32(Console.ReadLine());
num2 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("menu");
Console.WriteLine("enter 1 for addition");
Console.WriteLine("enter 2 for substraction");
Console.WriteLine("enter 3 for multiplication");
Console.WriteLine("enter 4 for division");
Console.WriteLine("please enter your opnion");
option = Convert.ToInt32(Console.ReadLine());
switch(option)
{
case 1:
result = num1 + num2;
Console.WriteLine("addition " + result);
break;
case 2:
result = num1 - num2;
Console.WriteLine("sub " + result);
break;
case 3:
result = num1 * num2;
Console.WriteLine("mul " + result);
break;
case 4:
result = num1 / num2;
Console.WriteLine("div " + result);
break;
default:
Console.WriteLine("invalid option " );
break;

}
Console.ReadLine();
}

}
}

Output:

please enter firstnumber and second number


23
34
menu
enter 1 for addition
enter 2 for substraction
enter 3 for multiplication
enter 4 for division
please enter your opnion
1
addition 57
Program:-16
16. Program to perform Nested if condition.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication9
{
class Program
{
static void Main(string[] args)
{
int a;
Console.WriteLine("enter a value");
a = int.Parse(Console.ReadLine());
if (a > 0)
{
if (a < 10)
{
Console.WriteLine("entered number is positive
and single digit");
}
else
{
Console.WriteLine("entered number is positive
and not single");
}
}

Console.ReadLine();
}
}
}

Output:

enter a value
9
entered number is positive and single digit
Program:-17
17. Program to perform else if ladder.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication9
{
class Program
{
static void Main(string[] args)
{
int a;
Console.WriteLine("enter a value");
a = int.Parse(Console.ReadLine());
if (a == 0)
{
Console.WriteLine("entered value is zero");
}
else if (a == 1)
{
Console.WriteLine("entered value is one");
}
else if (a == 2)
{
Console.WriteLine("entered value is two");
}
else if (a == 3)
{
Console.WriteLine("entered value is three");
}

Console.ReadLine();
}
}
}

Output:

enter a value
1
entered value is one
Program:-18
18. Program for method.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication4
{
class methodprogram
{
static int sum(int x,int y)
{
return (x + y);
}
static void Main(string[] args)
{
int a, b;
Console.WriteLine("enter a value:");
a = int.Parse(Console.ReadLine());
Console.WriteLine("enter b value:");
b = int.Parse(Console.ReadLine());
Console.WriteLine("sum of a and b is:{0}", sum(a, b));
Console.WriteLine("sub of a and b is :{0}", (a - b));
Console.ReadKey();

}
}
}

Output:

enter a value:
2
enter b value:
3
sum of a and b is:5
sub of a and b is :-1
Program:-19
19. program for method-II.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication4
{
class method2
{
static void xyz(int x, int y)
{
Console.WriteLine("sum:{0}", x + y);
Console.WriteLine("sub:{0}", x - y);
Console.WriteLine("mul:{0}", x * y);
}
static void Main(string[] args)
{
int a, b;
Console.WriteLine("enter a value");
a = int.Parse(Console.ReadLine());
Console.WriteLine("enter b value");
b = int.Parse(Console.ReadLine());
xyz(a, b);
Console.WriteLine("rem:{0}", a % b);
Console.ReadKey();
}
}
}

Output:

enter a value
23
enter b value
56
sum:79
sub:-33
mul:1288
rem:23
Program:-20
20. write a program using single dimensional array.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
int []A = new int[4]{10,20,30,40};
Console.WriteLine("elements");
for (int i = 0; i < 4; i++)
{
Console.WriteLine(A[i] + " ");

}
Console.Read();
}
}
}

Output:

elements
10
20
30
40
Program:-21
21. Program to print Two dimensional array.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication5
{
class two_dimensional
{
public static void Main(string[] args)
{
int [ , ]A = new int[3,4] {{1,2,3,1},{6,9,4,2},{2,1,5,1}};
Console.WriteLine("elements");
for (int r = 0; r < 3; r++)
{
for (int c = 0; c < 3; c++)
{
Console.Write(A[r, c] + " ");
}
Console.WriteLine();
}

Console.Read();

}
}
}

Output:

elements
1 2 3
6 9 4
2 1 5
Program:-22
22. Program to print Jagged array.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication5
{
class jagged_array
{
public static void Main(string[] args)
{
int[][] A = new int[3][];
A[0] = new int[4] { 10, 20, 30, 40 };
A[1] = new int[2] { 10, 20 };
A[2] = new int[3] { 10, 20, 30 };
Console.WriteLine("elements");
for (int r = 0; r < A.Length; r++)
{
for (int c = 0; c < A[r].Length; c++)
{
Console.Write(A[r][c] + " ");
}
Console.WriteLine();

}
Console.Read();
}
}
}

Output:

elements
10 20 30 40
10 20
10 20 30
Program:-23
23. Program to perform constructors.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication5
{
class clsemployee1
{
int empid;
string ename;
string eAddress;
int eage;
public clsemployee1(){
this.empid = 111;
this.ename = "lav";
this.eAddress = "hyd";
this.eage = 20;
}
public void displaydata()
{
Console.WriteLine("employee details:");
Console.WriteLine("empid is:"+this.empid);
Console.WriteLine("ename is:"+this.ename);
Console.WriteLine("eAddress is:"+this.eAddress);
Console.WriteLine("eage is:"+this.eage);
}
}
class clsdconst{
static void Main(string []args){
clsemployee1 e = new clsemployee1();
e.displaydata();
Console.Read();
}
}
}
Output:
employee details:
empid is:111
ename is:lav
eAddress is:hyd
eage is:20
Program:-24
24. Program to perform Enumeration operation.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication5
{
class enumeration
{
enum days { sun, mon, tues, wed, thurs, 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.ReadKey();
}
}
}

Output:

monday :1
friday :5
Program:-25
25. Program to perform Structures in c#.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication5
{
struct Books
{
public string title;
public string author;
public string subject;
public string book_id;
};
public class structure
{
public static void Main(string[] args)
{
Books book1;
Books book2;
book1.title = "c programming";
book1.author = "nuha ali";
book1.subject = "c programming tutorials";
book1.book_id = "3456";
book2.title = "telecom building";
book2.author = "zuha ali";
book2.subject = "telecom builiding tutorials";
book2.book_id = "2345";
Console.WriteLine("book1 title:{0}", book1.title);
Console.WriteLine("book1 author:{0}", book1.author);
Console.WriteLine("book1 subject:{0}", book1.subject);
Console.WriteLine("book1 book id:{0}", book1.book_id);
Console.WriteLine("book2 title:{0}", book2.title);
Console.WriteLine("book2 author:{0}", book2.author);
Console.WriteLine("book2 subject:{0}", book2.subject);
Console.WriteLine("book2 book id:{0}", book2.book_id);
Console.ReadKey();
}
}
}
Output:

book1 title:c programming


book1 author:nuha ali
book1 subject:c programming tutorials
book1 book id:3456
book2 title:telecom building
book2 author:zuha ali
book2 subject:telecom builiding tutorials
book2 book id:2345
Program:-26
26. Program to perform Single inheritance in c#.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication6
{
class clsbranch
{
int Bcode;
string Bname;
string Baddress;
public void GetBranchData()
{
Console.WriteLine("Enter branch details:");
this.Bcode = Convert.ToInt32(Console.ReadLine());
this.Bname = Console.ReadLine();
this.Baddress = Console.ReadLine();
}
public void DisplayBranchData()
{
Console.WriteLine("Branch details are :");
Console.WriteLine("branch code is :" + this.Bcode);
Console.WriteLine("branch name is :" + this.Bname);
Console.WriteLine("branch address is :" +
this.Baddress);
}
}
class clsemployee5 : clsbranch
{
int empid;
string ename;
string eaddress;
int eage;
public void GetEmpData()
{
Console.WriteLine("enter employee details:");
this.empid = Convert.ToInt32(Console.ReadLine());
this.ename = Console.ReadLine();
this.eaddress = Console.ReadLine();
this.eage = Convert.ToInt32(Console.ReadLine());
}
public void DisplayEmpData()
{
Console.WriteLine("emp details are:");
Console.WriteLine("emp id is " + this.empid);
Console.WriteLine("emp name is " + this.ename);
Console.WriteLine("emp address is " + this.eaddress);
Console.WriteLine("emp age is " + this.eage);

}
}
class clsInheritance
{
static void main(String[] args)
{
clsemployee5 obj1 = new clsemployee5();
obj1.GetBranchData();
obj1.GetEmpData();
obj1.DisplayBranchData();
obj1.DisplayEmpData();
}
}
}

Output:

enter emp details:


23
lavanya
hyd
20
emp details are:
empid is:23
empname is:lavanya
empAddress is:hyd
empage is:20
Program:-27
27. Program to perform abstraction in c#.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication6
{
class Program
{
int empid;
string empname;
string empaddress;
int empage;
public int pempid
{
set
{
empid = value;
}
get
{
return empid;
}
}
public string pempname
{
set
{
empname = value;
}
get
{
return empname;
}
}
public string pempaddress
{
set
{
empaddress = value;
}
get
{
return empaddress;
}
}
public int pempage
{
set
{
empage = value;
}
get
{
return empage;
}
}
class clsproperties
{
static void Main(string[] args)
{
Program obj = new Program();
Console.WriteLine("enter emp details:");
obj.pempid = Convert.ToInt32(Console.ReadLine());
obj.pempname = Console.ReadLine();
obj.pempaddress = Console.ReadLine();
obj.pempage = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("emp details are:");
Console.WriteLine("empid is:"+obj.pempid);
Console.WriteLine("empname is:" + obj.pempname);
Console.WriteLine("empAddress is:" +
obj.pempaddress);
Console.WriteLine("empage is:" + obj.pempage);
Console.ReadKey();

}
}
}
}

Output:

enter emp details:


59
lavanya
hyd
23
emp details are:
empid is:59
empname is:lavanya
empAddress is:hyd
empage is:23
Program:-28
28. Program to perform encapsulation.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication8
{
class employee
{
int empid;
string ename;
string eadd;
public void GetData()
{
Console.WriteLine("enter the emp details");
this.empid = Convert.ToInt32(Console.ReadLine());
this.ename = Console.ReadLine();
this.eadd = Console.ReadLine();
}
public void Display()
{
Console.WriteLine("The details of emp are");
Console.WriteLine("empid is " + this.empid);
Console.WriteLine("emp name is " + this.ename);
Console.WriteLine("emp address is " + this.eadd);

}
}
class clsEncapsulate
{
static void Main(String[] args)
{
employee obj1 = new employee();
obj1.GetData();
obj1.Display();
Console.ReadLine();
}
}
}
Output:

Enter the emp details


59
Lavanya
Hyd
The details of emp are
empid is 59
emp name is Lavanya
emp address is hyd
Program:-29
29. Program for method overloading.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication8
{
class sample
{
public int add(int x, int y)
{
return x + y;
}
public float add(float x, int y)
{
return x + y;
}
}
class clsoverload
{
public static void Main(String[] args)
{
sample obj1 = new sample();
Console.WriteLine("sum is:" + obj1.add(10, 20));
Console.WriteLine("sum is:" + obj1.add(12.5f, 20));
Console.ReadLine();
}
}
}

Output:

sum is:30
sum is:32.5
Program:-30
30. ASP .NET Program to make login form.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}

private void Form2_Load(object sender, EventArgs e)


{

private void textBox3_TextChanged(object sender, EventArgs


e)
{

private void button1_Click(object sender, EventArgs e)


{
string name = textBox1.Text;
string password = textBox2.Text;
if (name == "admin" && password == "cutm")
{
MessageBox.Show("your login is sucesfull");
}
}
}
}
Output:
Program:-31
31. ASP.net program to print simple calculator.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace windowsformbasics
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void label3_Click(object sender, EventArgs e)


{

private void textBox1_TextChanged(object sender, EventArgs


e)
{

int a, b, c;
private void button1_Click(object sender, EventArgs e)
{
a = Convert.ToInt32(txtNum1.Text);
b = Convert.ToInt32(txtNum2.Text);
c = a + b;
txtResult.Text = c.ToString();
}

private void button2_Click(object sender, EventArgs e)


{
a = Convert.ToInt32(txtNum1.Text);
b = Convert.ToInt32(txtNum2.Text);
c = a - b;
txtResult.Text = c.ToString();
}

private void button3_Click(object sender, EventArgs e)


{
a = Convert.ToInt32(txtNum1.Text);
b = Convert.ToInt32(txtNum2.Text);
c = a * b;
txtResult.Text = c.ToString();
}

private void button4_Click(object sender, EventArgs e)


{
a = Convert.ToInt32(txtNum1.Text);
b = Convert.ToInt32(txtNum2.Text);
if (b == 0)
{
MessageBox.Show("second number cant be zero");
txtNum2.Focus();
}
else
{
c = a / b;
txtResult.Text = c.ToString();
}
}

private void txtNum1_Leave(object sender, EventArgs e)


{
if (txtNum1.Text == "")
{
MessageBox.Show("enter any data");
txtNum1.Focus();
}
}

private void txtNum2_Leave(object sender, EventArgs e)


{
if (txtNum2.Text == "")
{
MessageBox.Show("enter any data");
txtNum2.Focus();
}
}

private void txtNum1_KeyPress(object sender,


KeyPressEventArgs e)
{
if (char.IsDigit(e.KeyChar) == false)
{
MessageBox.Show("enter digit only");
e.Handled = true;
}
}

private void txtNum2_KeyPress(object sender, KeyPressEventArgs e)


{
if (char.IsLetter(e.KeyChar) == true)
{
MessageBox.Show("enter digit only");
e.Handled = true;
}
}
}
}
Output:
Program:-32
32. Program to perform Web form application.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DropDownList2.Items.Add("India");
DropDownList2.Items.Add("Japan");
DropDownList2.Items.Add("china");
}
}

protected void DropDownList2_SelectedIndexChanged(object


sender, EventArgs e)
{
ListBox1.Items.Clear();
string selectedcountry = DropDownList2.SelectedValue;
if (selectedcountry == "India")
{
ListBox1.Items.Add("hyderabad");
ListBox1.Items.Add("mumbai");
ListBox1.Items.Add("vizag");
}

}
}
}
Output:

You might also like