Ap 6-15

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 45

Experiment No.

6
1.Write a program using method overloading to swap two integer numbers and swap two float
numbers.

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

namespace ConsoleApp20
{
class Swap
{
public static int num1, num2;
public static float flo1, flo2;
static void SwapNum(int a, int b)
{
num1 = a;
num2 = b;
Console.WriteLine($"Before Swapping number1: {num1} & number2: {num2}");
num1 = num1 + num2;
num2 = num1 - num2;
num1 = num1 - num2;
Console.WriteLine($"After Swapping number1: {num1} & number2: {num2}");
}

static void SwapNum(float a, float b)


{
flo1 = a;
flo2 = b;
Console.WriteLine($"Before Swapping number1: {flo1} & number2: {flo2}");
float temp = flo1;
flo1 = flo2;
flo2 = temp;
Console.WriteLine($"After swapping number1: {flo1} & number2: {flo2}");
}

static void Main(string[] args)


{
Console.Write("Enter Integer number1:");
num1 = int.Parse( Console.ReadLine() );
Console.Write("Enter Integer number2:");
num2 = int.Parse( Console.ReadLine() );

Console.Write("Enter float number1:");


flo1 = float.Parse( Console.ReadLine() );
Console.Write("Enter float number2:");
flo2 = float.Parse( Console.ReadLine() );

Console.WriteLine("\n______Swapping Integers______");
SwapNum(num1, num2);
Console.WriteLine("\n______Swapping Floats______");
SwapNum(flo1, flo2);
Console.ReadLine();
}
}
}
Output:
2. Write a program using method overloading to add the numbers by changing the number of
parameters.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp21
{
class Sum
{
static void AddNum(int a,int b)
{
Console.WriteLine($"Addition of {a} & {b}: {a + b}");
}
static void AddNum(int a,int b,int c)
{
Console.WriteLine($"Addition of {a},{b} & {c} : {a + b + c}");
}

static void Main(string[] args)


{
Console.Write("Enter Integer Number1:");
int num1 = int.Parse(Console.ReadLine());
Console.Write("Enter Integer Number2:");
int num2 = int.Parse(Console.ReadLine());

Console.Write("Enter Integer Number3:");


int num3 = int.Parse(Console.ReadLine());

Console.WriteLine("\n______Adding 2 integers______");
AddNum(num1,num2);
Console.WriteLine("\n______Adding 3 integers______");
AddNum(num1, num2, num3);
Console.ReadLine();
}
}
}
Output:
3.Write a program using method overloading to display the name and id of a student by changing
the order of the parameters.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp22
{
class Student
{
public int id;
public string name;

static void Display(int id,string name)


{
Console.WriteLine($"Student ID:{id} & Name: {name}");
}

static void Display(string name,int id)


{
Console.WriteLine($"Student Name: {name} and ID: {id}");
}

public static void Main()


{
Console.Write("Enter number of students:");
Student[] s = new Student[int.Parse(Console.ReadLine())];
for (int i = 0; i < s.Length; i++)
{
s[i] = new Student();
Console.WriteLine("______Enter Students Details______");
Console.WriteLine("Enter ID:");
s[i].id = int.Parse(Console.ReadLine());
Console.WriteLine("Enter Name:");
s[i].name = Console.ReadLine();
}

for (int i = 0; i < s.Length; i++)


{
Console.WriteLine("\n______By Passing ID then Name______");
Display(s[i].id, s[i].name);
Console.WriteLine("\n______By Passing Name then ID______");
Display(s[i].name, s[i].id);
}
Console.ReadLine();
}

}
}

Output:
4. Method Overloading
4.1. Without virtual and override keyword
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp24
{
internal class Add
{
public void AddNum(int a,int b)
{
Console.WriteLine("_____Base Class_____");
Console.WriteLine($"Addition of {a} and {b}: {a + b}");
}
}
class Adds : Add
{
public new void AddNum(int a,int b)
{
Console.WriteLine("_____Derived Class_____");
Console.WriteLine($"Addition of {a} ,{b}:{a+b}");
Console.WriteLine("_____By using Base keyword_____");
base.AddNum(a,b);
}

static void Main(string[] args)


{
Console.WriteLine("Enter Integer Number1:");
int number1 = int.Parse(Console.ReadLine());
Console.WriteLine("Enter Integer Number2:");
int number2 = int.Parse(Console.ReadLine());

Add add = new Add();


Console.WriteLine("\n____By calling Method using base class object____");
add.AddNum(number1,number2);

add = new Adds();


Console.WriteLine("\n____By calling Method passing derived class object____");
add.AddNum(number1,number2);

Adds adds = new Adds();


Console.WriteLine("\n____By calling method using derived class object____");
adds.AddNum(number1,number2);
Console.ReadLine();
}
}
}

Output:
4.2. With virtual and override keyword
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp25
{
internal class Add
{
public virtual void AddNum(int a,int b)
{
Console.WriteLine("_____Base Class_____");
Console.WriteLine($"Additionof {a},{b}: {a+b}");
}
}
class Adds:Add
{
public override void AddNum(int a, int b)
{
Console.WriteLine("_____Derived Class_____");
Console.WriteLine($"Addition of {a},{b}: {a + b}");
Console.WriteLine("____By using Base keyword____");
base.AddNum(a, b);
}
static void Main(string[] args)
{
Console.Write("Enter Integer number1:");
int number1 = int.Parse(Console.ReadLine());
Console.Write("Enter Integer number2:");
int number2 = int.Parse(Console.ReadLine());

Add add = new Add();


Console.WriteLine("\n____By calling method usnig base class object____");
add.AddNum(number1, number2);

add = new Adds();


Console.WriteLine("\n____By calling method passing derived class object____");
add.AddNum(number1, number2);

Adds adds = new Adds();


Console.WriteLine("\n____By calling method using derived class object____");
adds.AddNum(number1, number2);
Console.ReadLine();

}
}

Output:
5. Method Hiding
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp26
{
internal class Add
{
public void AddNum(int a,int b)
{
Console.WriteLine("_____Base Class_____");
Console.WriteLine($"Addition of {a},{b}:{a + b}");
}
}

class Adds:Add
{
public new void AddNum(int a,int b)
{
Console.WriteLine("____Derived class____");
Console.WriteLine($"Addition of {a},{b}:{a + b}");
Console.WriteLine("____By using base keyword____");
base.AddNum(a,b);
}

static void Main(string[] args)


{
Console.Write("Enter Integer number1:");
int number1 = int.Parse(Console.ReadLine());
Console.WriteLine("Enter integer number2:");
int number2 = int.Parse(Console.ReadLine());

Adds adds = new Adds();


Console.WriteLine("\n____By calling method using derived class object____");
adds.AddNum(number1,number2);
Console.ReadLine();
}
}
}

Output:
Experiment No. 7
1. Program to implement the following multiple inheritance using interface
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp27
{
public interface Gross
{
int TA { get; set; }
int DA { get; set; }
void Gross_sal();
}
internal class Employee
{
public string Name;
public int bsal;
public void Basic_sal()
{
Console.Write("Enter Name:");
Name = Console.ReadLine();
Console.Write("Enter basic salary:");
bsal = int.Parse(Console.ReadLine());
}
}

class Salary : Employee, Gross


{
public int HRA { get; set; }
private int ta, da;
public int TA
{
get { return ta; }
set { ta = value; }
}
public int DA
{
get { return da; }
set { da = value; }
}

void Gross.Gross_sal()
{
Console.Write("Enter TA:");
TA = int.Parse(Console.ReadLine());
Console.Write("Enter DA:");
DA = int.Parse(Console.ReadLine());
Console.Write("Enter HRA:");
HRA = int.Parse(Console.ReadLine());
}

void Display_sal()
{
Console.WriteLine($"Name:{Name}");
Console.WriteLine($"Basic salary:{bsal} Gross Salary:{TA + DA +HRA} Total Salary:{bsal + TA + DA +
HRA}");
}

static void Main(string[] args)


{
Console.Write("Enter Number of Employees:");
Salary[] s = new Salary[int.Parse(Console.ReadLine())];
Gross[] gross = s;

for(int i=0;i<gross.Length;i++)
{
s[i] = new Salary();
s[i].Basic_sal();

gross[i] = s[i];
gross[i].Gross_sal();
s[i].Display_sal();
}
Console.ReadLine();
}
}
}

Output:
2. Program to implement default implementation and Explicit implementation using interface

2.1 Default implementation

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

namespace ConsoleApp28
{
public interface Intf1
{
void Display();
}

internal class defImple : Intf1


{
public void Display()
{
string name;
Console.Write("Enter name:");
name = Console.ReadLine();
Console.WriteLine("This is implemented method from the interface");
Console.WriteLine($"Hello....!{name}");
}
}

internal class Program


{
private static void Main(string[] args)
{
defImple def = new defImple();
Intf1 intf1 = def;
intf1.Display();
Console.ReadLine();
}
}
}
Output:
3. Program to calculate the area of square using abstract class and abstract method

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

namespace ConsoleApp30
{
public abstract class Squares
{
public abstract void Area();
}

class Calc : Squares


{
public override void Area()
{
double side;
Console.WriteLine("Enter Value of side:");
side = double.Parse(Console.ReadLine());
Console.WriteLine($"Area of Square is:{side * side}");
}

static void Main(string[] args)


{
Calc cal = new Calc();
cal.Area();
Console.ReadLine();

}
}
}

Output:

4. Program to implement the following non-abstract and abstract method using abstract class

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

namespace ConsoleApp31
{
public abstract class AbstractClass
{
public void AddTwoNumbers(int a,int b)
{
Console.WriteLine($"Addition of {a}&{b} is:{a + b}");
}
public abstract void MultiplyTwoNumbers(int a, int b);
}
class Calc : AbstractClass
{
public override void MultiplyTwoNumbers(int a, int b)
{
Console.WriteLine($"Multiplication of {a}&{b} is:{a * b}");
}

static void Main(string[] args)


{
Calc cal = new Calc();
Console.Write("Enter First Number:");
int num1 = int.Parse(Console.ReadLine());
Console.WriteLine("Enter second number:");
int num2 = int.Parse(Console.ReadLine());
cal.AddTwoNumbers(num1, num2);
cal.MultiplyTwoNumbers(num1, num2);
Console.ReadLine();
}
}
}

Output:
Experiment No.8
1. Write a program to create an enum . here an enum with name month is created and its
data members are the name of months like Jan,Feb,Mar,Apr,May,etc. Now lets try to
print the default integer values of these enums.

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

namespace ConsoleApp32
{
public class Months
{
public enum months { Jan = 1, Feb, March, April, May, June, July, Aug, Sep, Oct, Nov, Dec };
static void Main(string[] args)
{
Console.WriteLine($"Jan:{(int)months.Jan}");
Console.WriteLine($"Feb:{(int)months.Feb}");
Console.WriteLine($"March:{(int)months.March}");
Console.WriteLine($"Aprtil:{(int)months.April}");
Console.WriteLine($"May:{(int)months.May}");
Console.WriteLine($"June:{(int)months.June}");
Console.WriteLine($"July:{(int)months.July}");
Console.WriteLine($"Aug:{(int)months.Aug}");
Console.WriteLine($"Sep:{(int)months.Sep}");
Console.WriteLine($"Oct:{(int)months.Oct}");
Console.WriteLine($"Nov:{(int)months.Nov}");
Console.WriteLine($"Dec:{(int)months.Dec}");

Console.ReadLine();
}
}
}
Output:
2. Write a program to create an enum . Here an enum with name, gender is created and
its data members are the name of Male, Female, Unknown. Now lets try to print the
Name and Gender(Using Switch case)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Text;
using System.Threading.Tasks;

namespace Enumpack
{
enum Gender { Male=1,Female=2,Unknown=3};
public class Info
{
string name;
int genderid;
public static string Getgender(int gender)
{
switch (gender)
{
case 1:
if ((int)Gender.Male == gender)
{
return "Male";
}
retun null;

case 2:
if ((int)Gender.Female == gender)
{
return "Female";
}
return null;
case 3:
if ((int)Gender.Unknown == gender)
{
return "Unkwown";
}
return null;
default return "Invalid Data for Gender";
}
}
public static void main(string[] args)
{
Console.Write("Enter Number of students:");
int size = int.Parse(Console.ReadLine());
Info[] infos = new Info[size];
Console.WriteLine("gender: 1-Male, 2-Female, 3-Unknown");
for (int i = 0; i < size; i++)
{
infos[i] = new Info();
Console.Write("Enter Name:");
infos[i].name = Console.ReadLine();
Console.Write("Enter Gender Value:");
infos[i].genderid = int.Parse(Console.ReadLine());
}
Console.WriteLine("\n_____Entered Details_____");
for (int i = 0; i < size; i++)
{
Console.WriteLine($"Name={infos[i].name}&&Gender={Getgender(infos[i].genderid)}");
}
Console.ReadLine();
}
}
}

Output:

Experiment No.9
1. Write a program to accept a number form the user and throw an exception if the number is
not an even number

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

namespace ConsoleApp34
{
internal class Excep
{
static void Main(string[] args)
{
Console.Write("Enter Even Number:");
int num = int.Parse(Console.ReadLine());
if(num%2!=0)
{
throw new Exception("Number is not an even number");
}
Console.WriteLine("Even Number");
Console.ReadLine();
}
}
}
Output:

2. Write a program to accept a two number form the user and divide the number and multiple
try catch block exception.(Format Exception, Overflow Exception,DivideBy Zero
Exception,Exception).

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Channels;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp35
{
internal class Excep
{
static void Main(string[] args)
{
Console.Write("Enter 1st number:");
int num = int.Parse(Console.ReadLine());
Console.Write("Enter end number:");
int num1 = int.Parse(Console.ReadLine());

try
{
Console.WriteLine($"Division is:{(num / num1)}");
}
catch (DivideByZeroException e)
{
Console.WriteLine($"\nError:{e}");
}
try
{
num = int.Parse("v");
Console.WriteLine($"Conversion is:{(num * 999999999999)}");
}

catch (FormatException e)
{
Console.WriteLine($"\nError:{e}");

}
try
{
char b = Convert.ToChar(num);
Console.WriteLine($"Conversion is:{b}");
}

catch (OverflowException e)
{
Console.WriteLine($"\nError:{e}");
}
try
{
num = int.Parse("1.5");
}

catch (Exception e)
{
Console.WriteLine($"\nError:{e}");
}
Console.ReadLine();
}
}
}
Output:

3. Write a program to user-Defined Exception

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

namespace ConsoleApp36
{
internal class InvalidMarksExcep:Exception
{
public InvalidMarksExcep(String msg)
: base(msg)
{
Console.WriteLine("Exception Occured");
}
}

class UserDefinedExcep
{
public static void Main(string[] args)
{
try
{
Console.Write("Enter your marks:");
int marks = int.Parse(Console.ReadLine());
if (marks>100 || marks<1)
{
throw new InvalidMarksExcep("Marks must be between 0-100");

}
}
catch(InvalidMarksExcep e)
{
Console.WriteLine(e);
}
Console.ReadLine();
}
}
}

Output:

Experiment No.10
1. Study of boxing and Unboxing

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

namespace ConsoleApp37
{
internal class Boxing
{
static void Main(string[] args)
{
Console.Write("Enter Number:");
int myVal = int.Parse(Console.ReadLine());
//boxing
object myBoxed = myVal;
//unboxing
int myUnBoxed = (int)myBoxed;

Console.WriteLine($"Value from variable:{myVal}");


Console.WriteLine($"Value from object passed from variable:{myBoxed}");
Console.WriteLine($"Value from variable passed from object:{myUnBoxed}");

int[] arra = new int[5];


//boxing
arra[0] = myVal;
//unboxing
int val = (int)arra[0];
Console.WriteLine("Value Passed to Array from variables:" + arra[0]);
Console.WriteLine("Value Passed from Array to variable:" + val);
Console.ReadLine();
}
}
}
Output:

2. If you have two integers stored in variable var1 & var2, what Boolean test can you perform
to see if not both numbers are greater than 10?

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

namespace ConsoleApp38
{
internal class Grt10
{
static void Main(string[] args)
{
Console.Write("Enter var1 value:");
int var1 = int.Parse(Console.ReadLine());
Console.Write("Enter var2 value:");
int var2 = int.Parse(Console.ReadLine());

if(var1>=10 && var2>=10)


{
Console.WriteLine("Both values cannot be greater than or equal to 10");
Console.ReadLine();
}
else if(var1>=10)
{
Console.WriteLine("Variable 1 greater tahn or equal to 10");
Console.ReadLine();
}
else if(var2>=10)
{
Console.WriteLine("Variable 2 greater than or equal to 10");

Console.ReadLine();
}
else
{
Console.WriteLine("Both Values are less than 10");
Console.ReadLine();
}
}
}
}

Output:
Experiment No.11
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;
using static System.Net.Mime.MediaTypeNames;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace EXP11
{
public partial class Form1 : Form
{
string rs="";

public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{

rs = label2.Text;
DataTable dt = new DataTable();
try
{
var v = dt.Compute(rs, "");
label1.Text = v.ToString();
}
catch (Exception ex)
{
label1.Text = ex.Message;
}
}

private void button2_Click(object sender, EventArgs e)


{
rs+=("1");
label2.Text = rs;
}

private void button3_Click(object sender, EventArgs e)


{
rs+="2";
label2.Text = rs.ToString();
}

private void button4_Click(object sender, EventArgs e)


{
rs+="3";
label2.Text = rs.ToString();
}
private void button13_Click(object sender, EventArgs e)
{
rs+="4";
label2.Text = rs.ToString();
}

private void button12_Click(object sender, EventArgs e)


{
rs+="5";
label2.Text = rs.ToString();
}

private void button11_Click(object sender, EventArgs e)


{
rs+="6";
label2.Text = rs.ToString();
}

private void button17_Click(object sender, EventArgs e)


{
rs+="7";
label2.Text = rs.ToString();
}

private void button16_Click(object sender, EventArgs e)


{
rs+="8";
label2.Text = rs.ToString();
}

private void button15_Click(object sender, EventArgs e)


{
rs+="9";
label2.Text = rs.ToString();
}

private void button21_Click(object sender, EventArgs e)


{
rs+="00";
label2.Text = rs.ToString();
}

private void button20_Click(object sender, EventArgs e)


{
rs+="0";
label2.Text = rs.ToString();
}

private void button19_Click(object sender, EventArgs e)


{
rs+=".";
label2.Text = rs.ToString();
}

private void button14_Click(object sender, EventArgs e)


{
try
{
int a = rs.Length - 1;
if (rs.Length != 0 && rs[a] != '%' && rs[a] != '+' && rs[a] != '-' && rs[a] != '*' && rs[a] != '/')
{
rs +="+";
label2.Text = rs.ToString();
}
}catch (Exception ex) { }
}

private void button10_Click(object sender, EventArgs e)


{
try
{
int a = rs.Length - 1;
if (rs.Length != 0 && rs[a] != '%' && rs[a] != '+' && rs[a] != '-' && rs[a] != '*' && rs[a] != '/')
{
rs += "-";
label2.Text = rs.ToString();
}
}
catch (Exception ex) { }
}

private void button5_Click(object sender, EventArgs e)


{
try
{
int a = rs.Length - 1;
if (rs.Length != 0 && rs[a] != '%' && rs[a] != '+' && rs[a] != '-' && rs[a] != '*' && rs[a] != '/')
{
rs += "*";
label2.Text = rs.ToString();
}
}
catch (Exception ex) { }
}

private void button6_Click(object sender, EventArgs e)


{
try
{
int a = rs.Length - 1;
if (rs.Length != 0 && rs[a] != '%' && rs[a] != '+' && rs[a] != '-' && rs[a] != '*' && rs[a] != '/')
{
rs += "/";
label2.Text = rs.ToString();
}
}
catch (Exception ex) { }
}

private void button8_Click(object sender, EventArgs e)


{
try
{
int a=rs.Length-1;
if (rs.Length != 0 && rs[a] != '%' && rs[a] != '+' && rs[a] != '-' && rs[a] != '*' && rs[a] != '/')
{
rs += "%";
label2.Text = rs.ToString();
}

}
catch (Exception ex) { }
}

private void button9_Click(object sender, EventArgs e)


{
rs = "";
label2.Text = rs;
label1.Text = rs;
}

private void button7_Click(object sender, EventArgs e)


{
int a = rs.Length - 1;
rs=rs.Remove(a);
label2.Text = rs;
}

private void button18_Click(object sender, EventArgs e)


{
rs = label2.Text;
DataTable dt = new DataTable();
try
{
var v = dt.Compute(rs, "");
label1.Text = v.ToString();
}
catch (Exception ex)
{
label1.Text = ex.Message;
}
}
}
}
Output:
Experiment No.12

Form 1
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;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Button;
using System.Xml.Linq;

namespace EXP12
{
public partial class Form1 : Form
{
public static string name, classnm, dept, lang;

private void label1_Click(object sender, EventArgs e)


{

public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
name = textBox1.Text;
lang = "";
try
{
if (radioButton1.Checked == true)
{
classnm = radioButton1.Text;
}
else if (radioButton2.Checked == true)
{
classnm = radioButton2.Text;
}
else if (radioButton3.Checked == true)
{
classnm = radioButton3.Text;
}
dept = comboBox1.SelectedItem.ToString();
if (checkBox1.Checked == true)
{
lang += checkBox1.Text + " ";
}
if (checkBox2.Checked == true)
{
lang += checkBox2.Text + " ";
}
var myForm = new Form2();
myForm.Show();
}
catch (Exception ex) { }

}
}
}

Form 2

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;
using System.Xml.Linq;

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

private void Form2_Load(object sender, EventArgs e)


{
label1.Text = "Name: " + Form1.name+"\nClass: "+Form1.classnm+ "\nDepartment: " + Form1.dept+ "\
nLanguages:" + Form1.lang;
}
}
}

Output:
Experiment No.13
using System.Net.Mail;
using System.Text.RegularExpressions;

namespace WinFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public string check;
private void button1_Click(object sender, EventArgs e)
{
string email = textBox2.Text;
check = "";
string pattern = null;
if (!Regex.IsMatch(textBox1.Text, @"^[A-Z][a-zA-Z]*$"))
check += "Invalid Name\n";
try
{
MailAddress m = new MailAddress(email);
}
catch (Exception ex)
{

check += "Invalid Mail Id\n";


}
if (!Regex.IsMatch(textBox3.Text, @"^\d{10}$"))
check += "Invalid Contact No.\n";

if (textBox4.Text.Length <= 5)
check += "Invalid Password\n";
if (!textBox4.Text.Equals(textBox5.Text))
check += "Password Dosen't Match\n";
MessageBox.Show(check, "Check Once Again", MessageBoxButtons.YesNoCancel);

}
}
}

Output:
13.2

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 MenuStrip
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void textBox1_TextChanged(object sender, EventArgs e)


{
}

private void button1_Click(object sender, EventArgs e)


{
richTextBox1.Enabled = false;
MessageBox.Show("Now you can read", "Change", MessageBoxButtons.OK);
}

private void button2_Click(object sender, EventArgs e)


{
richTextBox1.Enabled = true;
MessageBox.Show("Now you can write", "Change", MessageBoxButtons.OK);

private void button3_Click(object sender, EventArgs e)


{
if (richTextBox1.Text.Contains(textBox1.Text))
{

MessageBox.Show("Text Found", "Search Box", MessageBoxButtons.OK);

}
else
{
MessageBox.Show("Text Not Found", "Search Box ", MessageBoxButtons.OK);

}
}
}
Output:
Experiment No.14
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 EXP14
{
public partial class Form1 : Form
{
DataTable dt = new DataTable();
public Form1()
{
InitializeComponent();
dt.Columns.Add("Roll no");
dt.Columns.Add("Name");
dt.Columns.Add("Mob");
dt.Columns.Add("Course");
dt.Columns.Add("Year");
}
private void button1_Click(object sender, EventArgs e)
{
DataRow dr1 = dt.NewRow();
dr1["Roll no"] = textBox1.Text;
dr1["Name"] = textBox2.Text;
dr1["Mob"] = textBox3.Text;
dr1["Course"] = textBox4.Text;
dr1["Year"] = textBox5.Text;
dt.Rows.Add(dr1);
dataGridView1.DataSource = dt;
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
}
}

Output:
Experiment No.15

1.
using System.Data;
using System.Data.Odbc;
using System.Data.OleDb;

namespace Info
{

public partial class Form1 : Form


{
DataTable dt = new DataTable();
OleDbConnection conn;
OleDbDataAdapter myCmd;
public Form1()
{
InitializeComponent();
dt.Columns.Add("Roll Number");
dt.Columns.Add("Name");
dt.Columns.Add("Mobile Number");
dt.Columns.Add("Course");
dt.Columns.Add("Year");
conn = new OleDbConnection(@"Provider = Microsoft.ACE.OLEDB.12.0; Data Source = data\
Database31.accdb");
conn.Open();

DataSet dtSet = new DataSet();


myCmd = new OleDbDataAdapter("SELECT * FROM Info", conn);
myCmd.Fill(dtSet, "Info");
DataTable dTable = dtSet.Tables[0];
dataGridView1.DataSource = dtSet.Tables["Info"].DefaultView;
AddInfo();
}

public void AddInfo()


{
DataSet dtSet = new DataSet();
myCmd = new OleDbDataAdapter("SELECT * FROM Info order by eid", conn);
myCmd.Fill(dtSet, "Info");
DataTable dTable = dtSet.Tables[0];
dataGridView1.DataSource = dtSet.Tables["Info"].DefaultView;
}
private void button1_Click(object sender, EventArgs e)
{
DataSet dtSet = new DataSet();
var Command = new OleDbCommand("Insert into Info values(" + textBox1.Text + ", '" + textBox2.Text + "', '" +
textBox3.Text + "', '" + textBox4.Text + "');", conn);
Command.ExecuteNonQuery();
AddInfo();
}

private void panel1_Paint(object sender, PaintEventArgs e)


{

private void label6_Click(object sender, EventArgs e)


{

private void label7_Click(object sender, EventArgs e)


{

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)


{

private void dataGridView1_CellContentClick_1(object sender, DataGridViewCellEventArgs e)


{

private void textBox4_TextChanged(object sender, EventArgs e)


{

private void button2_Click(object sender, EventArgs e)


{
DataSet dtSet = new DataSet();

var Command = new OleDbCommand("Update Info set name= '" + textBox2.Text + "',email='" + textBox3.Text +
"',contact_number='" + textBox4.Text + "' where eid="+textBox1.Text+";", conn);
Command.ExecuteNonQuery();
AddInfo();
}

private void button3_Click(object sender, EventArgs e)


{
DataSet dtSet = new DataSet();
var Command = new OleDbCommand("Delete from Info Where eid=(" + textBox1.Text + ");", conn);
Command.ExecuteNonQuery();
AddInfo();
}
}
}

Output:

1.Insert
2.Update

3.Delete
2.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"


Inherits="WEBAPP.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<p>

<asp:GridView runat="server" AutoGenerateColumns="False" DataKeyNames="eid"


DataSourceID="SqlDataSource1" ID="ctl31" AllowPaging="True">
<Columns>
<asp:BoundField DataField="eid" HeaderText="eid" ReadOnly="True"
SortExpression="eid"></asp:BoundField>
<asp:BoundField DataField="name" HeaderText="name" SortExpression="name"></asp:BoundField>
<asp:BoundField DataField="email" HeaderText="email" SortExpression="email"></asp:BoundField>
<asp:BoundField DataField="contact_number" HeaderText="contact_number"
SortExpression="contact_number"></asp:BoundField>
</Columns>
</asp:GridView>
<asp:SqlDataSource runat="server" ID="SqlDataSource1" ConnectionString="<%$
ConnectionStrings:ConnectionString4 %>" ProviderName="<%$ ConnectionStrings:ConnectionString4.ProviderName
%>" SelectCommand="SELECT * FROM [Info]"></asp:SqlDataSource>
</p>
</div>
</form>
</body>
</html>

Output:

You might also like