Вы находитесь на странице: 1из 63

KONGU ENGINEERING COLLEGE

(Autonomous)
PERUNDURAI, ERODE 638052

School of Communication and Computer


Sciences
Department of Computer Science and
Engineering

LABORATORY MANUAL
(As per KEC Autonomous Curricula and Syllabi R2009)

11CS603
.NET Technologies
VI SEMESTER B.E. CSE

KONGU ENGINEERING COLLEGE


(Autonomous)
PERUNDURAI, ERODE 638052

School of Communication and Computer


Sciences
Department of Computer Science and
Engineering

LABORATORY MANUAL
(As per KEC Autonomous Curricula and Syllabi R2009)

11CS603
.NET Technologies

Prepared by,
[Ms.T.Karthikayini]

Approved by,
[Mr.R.Thangarajan]

11CS605 .NET LABORATORY


0

Objective:

To provide the basic knowledge in the .Net programming


To develop web applications using ASP.NET and C# Technologies

LIST OF EXPERIMENTS /EXERCISES

1.

Write a C# program to create a stack and implement the various stack operations. Define the
required constructor to initialize the data members and also destructor to free the memory

2.

Write a C# program to
implement the inheritance
overload the various operators

3.
Write a C# program to define and implement an interface in a class and also to extend and combine
interfaces.
4.
Write a C# program to

demonstrate the purpose of built in exceptions.

create a user defined exception.


5.
Write a C# program to perform object-oriented string matching and replacement in a given
document.
6.
Write a C# program to

create a delegate.

retrieve values from multiple delegates.


7.
Design a windows form in C# to register your resume through online mode. Identify the appropriate
controls to collect your personal details, education details starting from schools, project details, prizes &
ranks and extra-curricular activities.
8.
Write a C# program to

insert students academic and personal details into a Oracle/SQL Server database

retrieve the student details from the database for a given condition and populate the same
in a data-grid control.
9.
Create a Calculator web service in ASP.NET with arithmetic & trigonometric operations and write an
appropriate client code to access the calculator web service.
10.
Write a C# program to build a multi module and shared assembly.
11.
Write a C# program to invoke a method dynamically which resides in a remote machine and also
perform the required marshaling and un marshaling on the arguments passing to a remote method.
12.
Write a C# program to implement the producer - consumer problem by using threads and thread
synchronization.
REFERENCES / MANUALS/SOFTWARE:
1. Jesse Liberty , Donald Xie Programming C# 3.0, 5th Edition, OReilly Publications, 2007.
2. Jesse Liberty , Brian MacDonald Learning C# 3.0, OReilly Publications, ,2008
Software requirements
Operating System
Application Software

: Windows XP
: .NET 2.0 and above

SIMPLE C++ PROGRAMS


1. Factorial of a number
Program:
#include<iostream.h>
#include<conio.h>
void main()
{
int n,fact;
int rec(int); clrscr();
cout<<"Enter the number : ";
cin>>n;
fact=rec(n);
cout<<endl<<"Factorial of the numner is "<<fact<<endl;
getch();
}
rec(int x)
{
int f;
if(x==1)
return(x);
else
{
f=x*rec(x-1);
return(f);
}
}

Output:
Enter the number: 4
Factorial of the number is 24
2. Fibonacci series
Program
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a=0,b=1,c=0,n;
cout<<"Enter the number of terms you wanna see: ";
cin>>n;
cout<<a<<" "<<b<<" ";
for(int i=1;i<=n-2;i++)
{
c=a+b;
a=b;
b=c;
cout<<c<<" ";
}
getch();
}

Output
Enter the number of terms you wanna see: 8
0 1 1 2 3 5 8 13

1. Write a C# program to create a stack and implement the various stack operations. Define the
required constructor to initialize the data members and also destructor to free the memory.
Aim
To write a c# program to implement stack and its operations using constructor and destructor to
free the memory.
Algorithm
1. Start the program.
2. Define a class and create a constructor.
3. Assign the top of stack value as -1 inside the constructor.
4. Define functions for push, pop and display.
5. Inside push function insert the elements to the stack. If the stack is full display a message as stack
is full (overflow).
6. Inside pop function remove the elements from the stack. If the stack is empty display a message
as stack is empty.
7. Inside display function display the elements in the stack. If the stack is empty display empty
stack.
8. Stop the program.
Program
using System;
using System.Collections.Generic;
using System.Text;
namespace stack
{
class stc
{
int[] a = new int[10];
int i, k;
public stc()
{
i=-1;
k = 0;
}
public void push(int b)
{
if(i>2)
{
System.Console.WriteLine("Stack is full");
}
else
{
i++;
a[i]=b;
k++;
}
}
public void pop()
{
if (i == 0)
{
System.Console.WriteLine("Stack is empty");
}
else
{
i--;

k--;

}
public void display()
{
if(k==0)
{
System.Console.WriteLine("Stack is empty");
}
else
{
for (i = 0; i < k; i++)
System.Console.WriteLine(a[i]);
}
}
~stc()
{
System.Console.WriteLine("Destructor executed");
}

Main class
using System;
using System.Collections.Generic;
using System.Text;
namespace stack
{
class Program
{
static void Main(string[] args)
{
string s1, s2;
int a, n, e = 0;
stc s = new stc();
System.Console.WriteLine("Enter your option");
while (e < 1)
{
System.Console.WriteLine("1.PUSH 2.POP 3.DISPLAY
4.EXIT");
s1 = System.Console.ReadLine();
a = int.Parse(s1);
if (a == 1)
{
System.Console.WriteLine("Enter the element");
s2 = System.Console.ReadLine();
n = int.Parse(s2);
s.push(n);
}
else if (a == 2)
{
s.pop();
}
else if (a == 3)
{
System.Console.WriteLine("Elements in the stack:");
s.display();
}
else
{

}
}
}

e = 1;

Output

Result
Thus a C# program performing stack operations using constructor and destructor is successfully
implemented.

2. Write a C# program to implement the concept of inheritance and to overload the various
operators
Aim
To write a C# program to implement the concept of inheritance and to overload the different
operators.
Algorithm
1. Start the program.
2. Declare a class with a function for display.
3. Declare another class that inherits the first class.
4. Create constructor for the class with and without parameters for input.
5. Overload arithmetic operators, relational operators and explicit operator.
6. Display the output.
7. Stop the program.
Program
using System;
using System.Collections.Generic;
using System.Text;
namespace overload
{
class op
{
public int x1, y1;
public void show()
{
Console.WriteLine(x1 + "," + y1);
}
}
class a : op
{
public a()
{
x1 = 0;
y1 = 0;
}
public a(int x2, int y2)
{
x1 = x2;
y1 = y2;
Console.WriteLine("x1=" + x1);
Console.WriteLine("y1=" + y1);
}
public static a operator +(a x, a y)
{
a r = new a();
r.x1 = x.x1 + y.x1;
r.y1 = x.y1 + y.y1;
return r;
}
public static a operator ++(a x)
{
x.x1++;
x.y1++;
return x;

}
public static bool operator <(a x, a y)
{
if ((x.x1 < y.x1) && (x.y1 < y.y1))
return true;
else
return false;
}
public static bool operator >(a x, a y)
{
if ((x.x1 > y.x1) && (x.y1 > y.y1))
return true;
else
return false;

}
public static implicit operator int(a x)
{
return x.x1 * x.y1;
}

}
class Program
{
static void Main(string[] args)
{
int i;
Console.WriteLine("First operand");
a a1 = new a(2, 3);
Console.WriteLine("Second operand");
a a2 = new a(1, 2);
a c = new a();
Console.WriteLine("Addition:");
c = a1 + a2;
c.show();
a1++;
Console.WriteLine("Increment of first operator");
a1.show();
Console.WriteLine("Comparison between 1 & 2");
if (a2 < a1)
Console.WriteLine("a2<a1 is TRUE");
Console.WriteLine("Conversion to INT");
i = a1;
Console.WriteLine(i);
Console.WriteLine("Operation in the converted one");
i = a1 * 2;
Console.WriteLine(i);
Console.ReadLine();
}
}

Output

Result
Thus a c# program for implementing the concept of inheritance with operator overloading is
successfully executed.

3. Write a C# program to define and implement an interface in a class and also to extend and
combine interfaces.
Aim
To write a C# program to implement the concept of interface and also to extend and combine the
interface.
Algorithm
1. Start the program.
2. Create two interfaces. One extends the other interface.
3. Create a class and inherit the interface. Define the functions inside the class.
4. Create another class and inherit the other interface and define the functions inside it.
5. Inside the main class, create objects to the defined classes.
6. Using the created objects invoke the defined functions.
7. Display the output.
8. Stop the program.
Program
using System;
using System.Collections.Generic;
using S = System.Console;
using System.Text;
namespace it
{
public interface codein
{
String encode(String str);
String decode(String str);
}
public interface prop
{
int next
{
get;
set;
}
int this[int index]
{
get;
}
}
class Sicode : codein
{
public string encode(string str)
{
string sitext = "";
for (int i = 0; i < str.Length; i++)
sitext = sitext + (char)(str[i] + 1);
return sitext;
}
public string decode(string str)
{
string gtext = "";
for (int i = 0; i < str.Length; i++)
gtext = gtext + (char)(str[i] - 1);
return gtext;

}
}
class pind : prop
{
int val;
public pind()
{
val = 0;
}
// get or set value using a property
public int next
{
get
{
val += 2;
return val;
}
set
{
val = value;
}
}
// get a value using an index
public int this[int index]
{
get
{
val = 0;
for (int i = 0; i < index; i++)
val += 2;
return val;
}
}
}
Main class
class Coding
{
static void Main(string[] args)
{
codein cod;
String st;
int l;
Sicode sc = new Sicode();
string given;
string coded;
cod = sc;
S.WriteLine("Enter the text to decode");
st = S.ReadLine();
l = st.Length;
given = st;
coded = cod.encode(given);
given = cod.decode(coded);
Console.WriteLine("Given Text: " + given);
Console.WriteLine("Coded Text: " + coded);
pind ob = new pind();
S.WriteLine("\n");
for (int i = 0; i < 2; i++)
Console.WriteLine("Next value is " + ob.next);
Console.WriteLine("\nStarting at 20");
ob.next = 15;

for (int i = 0; i < 2; i++)


Console.WriteLine("Next value is " + ob.next);
Console.WriteLine("\nResetting to 0");
ob.next = 0;
for (int i = 0; i < 2; i++)
Console.WriteLine("Next value is " + ob[i]);
Console.ReadLine();
}
}

Output

Result
Thus a C# program for implementing the concept of interface along with combining and defining
it was successfully executed.

4. Write a C# program to demonstrate the purpose of built in exceptions and user defined
exceptions.
Aim
To write a C# program to demonstrate the purpose of built in exceptions and user defined
exceptions.
Algorithm
1. Start the program.
2. Create a class and declare it as base for overriding.
3. Use built in exception.
4. Create another class as bank with parameterized constructor for getting name, password, acc no
and initial balance.
5. Declare functions for deposit, withdrawal and balance.
6. Inside every function allow the user to access the option after providing the acc no and password.
7. Handle the exception if the amount to be withdrawn is greater than the available amount.
8. Use exception if the acc no and password mismatches.
9. Handle all the exceptions.
10. Display the output.
11. Stop the program.
Program
using System;
using System.Collections.Generic;
using System.Text;
namespace exp
{
class ex : ApplicationException
{
public ex() : base() { }
public ex(String a) : base(a) { }
public override string ToString()
{
return Message;
}
}
class bank
{
public String name, pass;
public int ac, bal;
public bank(String a, String b, int c, int d)
{
name = a;
pass = b;
ac = c;
bal = d;
}
public void deposit(int a, String p, int amt)
{
try
{
if (a != ac)
throw new ex("Acc no Mismatch");
try
{
if (p != pass)
throw new ex("Wrong Password");
try

if (amt < 0)
throw new ex("Incorrect Amount");
else
bal = bal + amt;

}
catch (ex e)
{
Console.WriteLine(e);
}
}
catch (ex e)
{
Console.WriteLine(e);
}

}
catch (ex e)
{
Console.WriteLine(e);
}
}

public void withdraw(int a, String p, int amt)


{
if (amt < bal)
{
try
{
if (a != ac)
throw new ex("Acc no Mismatch");
try
{
if (p != pass)
throw new ex("Wrong Password");
try
{
if (amt < 0)
throw new ex("Incorrect Amount");
else
bal = bal - amt;
}
catch (ex e)
{
Console.WriteLine(e);
}
}
catch (ex e)
{
Console.WriteLine(e);
}
}
catch (ex e)
{
Console.WriteLine(e);
}
}
else
Console.WriteLine("Please Enter lesser amt");
}

public void balance(int a, String p)


{
try
{
if (a != ac)
throw new ex("Acc no Mismatch");
try
{
if (p != pass)
throw new ex("Wrong Password");
else
{
Console.WriteLine("Name : " + name);
Console.WriteLine("Accno : " + ac);
Console.WriteLine("Balance : " + bal);
}
}
catch (ex e)
{
Console.WriteLine(e);
throw;
}
}
catch (ex e)
{
Console.WriteLine(e);
}
finally
{
Console.WriteLine("_________________________\nTh
anks for Banking\n");
}
}

}
//Console.WriteLine("Enter the accno "
class Program
{
static void Main(string[] args)
{
bank b1 = new bank("Sharan", "jasmine", 1234, 5000);
int ch;
int a = 0, am = 0;
string p = "";
/* b1.withdraw(a,p,am);
Console.WriteLine("Enter the Accno,pass,amt");
a=int.Parse(Console.ReadLine());
p=Console.ReadLine();
am=int.Parse(Console.ReadLine());*/
Console.WriteLine("Welcome To KEC");
do
{

Console.WriteLine("1.Deposit 2.Withdrawl 3.Balance 4.Exit");


ch = int.Parse(Console.ReadLine());
if (ch != 4)
{
Console.WriteLine("Enter the Accno and password:");
a = int.Parse(Console.ReadLine());
p = Console.ReadLine();
if (ch != 3)

Console.WriteLine("Enter the amount");


try
{
am = unchecked(int.Parse(Console.ReadLine()));
if (am < 0)
throw new ex("Incorrect amt");
}
catch (ex e)
{
Console.WriteLine(e);
}
catch (OverflowException e)
{
Console.WriteLine("Please Enter lesser Amount ");
}

}
}
else Console.WriteLine("Thanks for banking");
switch (ch)
{
case 1:
b1.deposit(a, p, am);
break;
case 2:
b1.withdraw(a, p, am);
break;
case 3:
b1.balance(a, p);
break;
}
} while (ch != 4);
}
}

Output

Result
Thus a c# program for exception handling with built in exception and user defined exceptions
was successfully executed.

5. Write a C# program to perform object-oriented string matching and replacement in a given


document.
Aim
To write a c# program to perform object-oriented string matching and replacement.
Algorithm
1.
2.
3.
4.
5.
6.
7.
8.
9.

Start the program


Include necessary header files
Declare a class
Get the string as input
Inside the main class, match the string and replace it depending on requirements.
Use patterns and regex.
Display the output
Stop the program

Program
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.IO;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
string input = "Sharan 103";
string pattern3 = "([0-9]+)";
string pattern2 = "text+";
string replacement = "kumar";
Regex rgx = new Regex(pattern3);
string result = rgx.Replace(input, replacement);
Console.WriteLine("Original String: {0}", input);
Console.WriteLine("Replacement String: {0}", result);
if (Regex.IsMatch(input, pattern2))
Console.WriteLine("match");
else
Console.WriteLine("not matching");
string content = "123abbbabbaaa123baaaabbbbcccaaa123cccbbb123";
string pattern = "a+"; if (Regex.IsMatch(content, pattern))
Console.WriteLine("Pattern Found");
else

Console.WriteLine("Pattern Not Found");


string input5 = "jasmine-sharan";
string pattern5 = "(-)";
string[] substrings = Regex.Split(input5, pattern5);
foreach (string match in substrings)
{
Console.WriteLine(match);
}
Console.ReadLine();
}
}

Output

Result
Thus a c# program to perform object-oriented string matching and replacement was
successfully executed.

6. Write a C# program to create a delegate and to retrieve values from multiple delegates
Aim
To write a c# program to create a delegate and to retrieve values from multiple delegates.
Algorithm
1. Start the program.
2. Create a class. Create a delegate with string as parameter.
3. Inside the class. Create method hello and bye with string as parameter.
4. Create function for operations such as copy, replace, concatenate etc.,
5. Inside the main class create references for deligates.
6. Assign values to it and multicast the deligates.
7. Display the result.
8. Stop the program.
Program
using System;
using System.Collections.Generic;
using System.Text;
namespace deli
{
delegate void del (string s);
class Program
{
static void hello(string s)
{
Console.WriteLine("\t String1:" + s);
}
static void bye(string s)
{
Console.WriteLine("\t String2:" + s);
}
static void replace(string s)
{
string v = s.Replace(s, "jasmine");
Console.WriteLine("\tReplaced string:" + v);
}
static void copy(string s)
{
string v = string.Copy(s);
Console.WriteLine("\tCopied string:" + v);
}
static void concatenate(string s)
{
Console.WriteLine("\tConcatenated string:" + s + "hrithika");
}
static void length(string s)
{
int a;
a = s.Length;
Console.WriteLine("\tLength of the string:" + a);
}
static void Main()
{
del a, b, c, d, e, f, g, h;
a = hello;
b = bye;
c = a + b;
d = c - a;

}
}

Console.WriteLine("Delegate
a("hi");
Console.WriteLine("Delegate
b("welcome");
Console.WriteLine("Delegate
c("jasmine");
Console.WriteLine("Delegate
d("hasini");
e = concatenate;
f = replace;
g = copy;
Console.WriteLine("Delegate
e("neha");
Console.WriteLine("Delegate
f("yashika");
Console.WriteLine("Delegate
g("britney spears");
h = length;
Console.WriteLine("Delegate
h("selena golmez");
Console.ReadLine();

a:");
b:");
c:");
d:");

e:");
f:");
g:");
h:");

Output

Result
Thus a C# program for implementing delegates and assigning values for multicast delegates was
successfully executed.

7. Design a windows form in C# to register your resume through online mode. Identify the
appropriate controls to collect your personal details, education details starting from schools, project
details, prizes & ranks and extra-curricular activities.
Aim
To design a windows form in C# for resume submission through online mode.
Algorithm
1. Start the program
2. Open a new C# windows form application
3. Create the interface as follows with the help of tools available in the tool box

4.
5.
6.
7.
8.
9.
10.

Add four buttons for submit, delete, clear and update.


Double click the buttons and add controls to it.
Create a database using MS-Access to store the data
Establish connection to the database.
Include controls to each button that has connection with the database
Display the output
Stop the program

Program
Program.cs
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace first
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}

Form1.Designer.cs
namespace first
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be
disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();

this.checkBox1 = new System.Windows.Forms.CheckBox();


this.checkBox2 = new System.Windows.Forms.CheckBox();
this.label4 = new System.Windows.Forms.Label();
this.textBox3 = new System.Windows.Forms.TextBox();
this.label6 = new System.Windows.Forms.Label();
this.label7 = new System.Windows.Forms.Label();
this.label8 = new System.Windows.Forms.Label();
this.label9 = new System.Windows.Forms.Label();
this.label10 = new System.Windows.Forms.Label();
this.textBox4 = new System.Windows.Forms.TextBox();
this.textBox5 = new System.Windows.Forms.TextBox();
this.textBox6 = new System.Windows.Forms.TextBox();
this.textBox7 = new System.Windows.Forms.TextBox();
this.label12 = new System.Windows.Forms.Label();
this.label13 = new System.Windows.Forms.Label();
this.label14 = new System.Windows.Forms.Label();
this.textBox8 = new System.Windows.Forms.TextBox();
this.listBox1 = new System.Windows.Forms.ListBox();
this.listBox2 = new System.Windows.Forms.ListBox();
this.listBox3 = new System.Windows.Forms.ListBox();
this.textBox9 = new System.Windows.Forms.TextBox();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.radioButton1 = new System.Windows.Forms.RadioButton();
this.radioButton2 = new System.Windows.Forms.RadioButton();
this.radioButton3 = new System.Windows.Forms.RadioButton();
this.radioButton4 = new System.Windows.Forms.RadioButton();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.groupBox3.SuspendLayout();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(15, 26);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(38, 13);
this.label1.TabIndex = 0;
this.label1.Text = "NAME";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(15, 67);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(30, 13);
this.label2.TabIndex = 1;
this.label2.Text = "DOB";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(15, 107);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(53, 13);
this.label3.TabIndex = 2;

this.label3.Text = "GENDER";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(107, 26);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(170, 20);
this.textBox1.TabIndex = 3;
this.textBox1.Text = "aaa";
this.textBox1.TextChanged += new
System.EventHandler(this.textBox1_TextChanged);
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(107, 60);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(100, 20);
this.textBox2.TabIndex = 4;
this.textBox2.Text = "12-9-1991";
this.textBox2.TextChanged += new
System.EventHandler(this.textBox2_TextChanged);
//
// checkBox1
//
this.checkBox1.AutoSize = true;
this.checkBox1.BackColor = System.Drawing.SystemColors.Control;
this.checkBox1.Location = new System.Drawing.Point(107, 103);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(49, 17);
this.checkBox1.TabIndex = 5;
this.checkBox1.Text = "Male";
this.checkBox1.UseVisualStyleBackColor = false;
this.checkBox1.CheckedChanged += new
System.EventHandler(this.checkBox1_CheckedChanged);
//
// checkBox2
//
this.checkBox2.AutoSize = true;
this.checkBox2.Location = new System.Drawing.Point(177, 103);
this.checkBox2.Name = "checkBox2";
this.checkBox2.Size = new System.Drawing.Size(60, 17);
this.checkBox2.TabIndex = 6;
this.checkBox2.Text = "Female";
this.checkBox2.UseVisualStyleBackColor = true;
this.checkBox2.CheckedChanged += new
System.EventHandler(this.checkBox2_CheckedChanged);
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(15, 151);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(91, 13);
this.label4.TabIndex = 7;
this.label4.Text = "FATHERS NAME";
//
// textBox3
//
this.textBox3.Location = new System.Drawing.Point(107, 144);
this.textBox3.Name = "textBox3";

this.textBox3.Size = new System.Drawing.Size(100, 20);


this.textBox3.TabIndex = 8;
this.textBox3.Text = "bbb";
this.textBox3.TextChanged += new
System.EventHandler(this.textBox3_TextChanged);
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(15, 49);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(14, 13);
this.label6.TabIndex = 10;
this.label6.Text = "X";
//
// label7
//
this.label7.AutoSize = true;
this.label7.Location = new System.Drawing.Point(15, 95);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(26, 13);
this.label7.TabIndex = 11;
this.label7.Text = "XLL";
//
// label8
//
this.label8.AutoSize = true;
this.label8.Location = new System.Drawing.Point(76, 16);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(80, 13);
this.label8.TabIndex = 12;
this.label8.Text = "PERCENTAGE";
//
// label9
//
this.label9.AutoSize = true;
this.label9.Location = new System.Drawing.Point(163, 16);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(103, 13);
this.label9.TabIndex = 13;
this.label9.Text = "YEAR OF PASSING";
//
// label10
//
this.label10.AutoSize = true;
this.label10.Location = new System.Drawing.Point(292, 16);
this.label10.Name = "label10";
this.label10.Size = new System.Drawing.Size(152, 13);
this.label10.TabIndex = 14;
this.label10.Text = "NAME OF THE INSTITUTION";
//
// textBox4
//
this.textBox4.Location = new System.Drawing.Point(79, 42);
this.textBox4.Name = "textBox4";
this.textBox4.Size = new System.Drawing.Size(77, 20);
this.textBox4.TabIndex = 15;
this.textBox4.Text = "98";
this.textBox4.TextChanged += new
System.EventHandler(this.textBox4_TextChanged);

//
// textBox5
//
this.textBox5.Location = new System.Drawing.Point(79, 92);
this.textBox5.Name = "textBox5";
this.textBox5.Size = new System.Drawing.Size(77, 20);
this.textBox5.TabIndex = 16;
this.textBox5.Text = "97";
this.textBox5.TextChanged += new
System.EventHandler(this.textBox5_TextChanged);
//
// textBox6
//
this.textBox6.Location = new System.Drawing.Point(295, 39);
this.textBox6.Name = "textBox6";
this.textBox6.Size = new System.Drawing.Size(149, 20);
this.textBox6.TabIndex = 19;
this.textBox6.TextChanged += new
System.EventHandler(this.textBox6_TextChanged);
//
// textBox7
//
this.textBox7.Location = new System.Drawing.Point(295, 89);
this.textBox7.Name = "textBox7";
this.textBox7.Size = new System.Drawing.Size(149, 20);
this.textBox7.TabIndex = 20;
this.textBox7.TextChanged += new
System.EventHandler(this.textBox7_TextChanged);
//
// label12
//
this.label12.AutoSize = true;
this.label12.Location = new System.Drawing.Point(12, 36);
this.label12.Name = "label12";
this.label12.Size = new System.Drawing.Size(51, 13);
this.label12.TabIndex = 22;
this.label12.Text = "SPORTS";
this.label12.Click += new
System.EventHandler(this.label12_Click);
//
// label13
//
this.label13.AutoSize = true;
this.label13.Location = new System.Drawing.Point(11, 69);
this.label13.Name = "label13";
this.label13.Size = new System.Drawing.Size(52, 13);
this.label13.TabIndex = 23;
this.label13.Text = "OTHERS";
//
// label14
//
this.label14.AutoSize = true;
this.label14.Location = new System.Drawing.Point(12, 146);
this.label14.Name = "label14";
this.label14.Size = new System.Drawing.Size(56, 13);
this.label14.TabIndex = 24;
this.label14.Text = "COLLAGE";
//
// textBox8
//

this.textBox8.Location = new System.Drawing.Point(79, 143);


this.textBox8.Name = "textBox8";
this.textBox8.Size = new System.Drawing.Size(77, 20);
this.textBox8.TabIndex = 25;
this.textBox8.Text = "94";
this.textBox8.TextChanged += new
System.EventHandler(this.textBox8_TextChanged);
//
// listBox1
//
this.listBox1.FormattingEnabled = true;
this.listBox1.Location = new System.Drawing.Point(166, 42);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(111, 17);
this.listBox1.TabIndex = 26;
this.listBox1.SelectedIndexChanged += new
System.EventHandler(this.listBox1_SelectedIndexChanged);
//
// listBox2
//
this.listBox2.FormattingEnabled = true;
this.listBox2.Location = new System.Drawing.Point(166, 92);
this.listBox2.Name = "listBox2";
this.listBox2.Size = new System.Drawing.Size(111, 17);
this.listBox2.TabIndex = 27;
this.listBox2.SelectedIndexChanged += new
System.EventHandler(this.listBox2_SelectedIndexChanged);
//
// listBox3
//
this.listBox3.FormattingEnabled = true;
this.listBox3.Location = new System.Drawing.Point(166, 143);
this.listBox3.Name = "listBox3";
this.listBox3.Size = new System.Drawing.Size(111, 17);
this.listBox3.TabIndex = 28;
this.listBox3.SelectedIndexChanged += new
System.EventHandler(this.listBox3_SelectedIndexChanged);
//
// textBox9
//
this.textBox9.Location = new System.Drawing.Point(295, 140);
this.textBox9.Name = "textBox9";
this.textBox9.Size = new System.Drawing.Size(149, 20);
this.textBox9.TabIndex = 29;
this.textBox9.TextChanged += new
System.EventHandler(this.textBox9_TextChanged);
//
// groupBox1
//
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Controls.Add(this.textBox1);
this.groupBox1.Controls.Add(this.textBox2);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Controls.Add(this.checkBox1);
this.groupBox1.Controls.Add(this.checkBox2);
this.groupBox1.Controls.Add(this.label4);
this.groupBox1.Controls.Add(this.textBox3);
this.groupBox1.Location = new System.Drawing.Point(117, 12);
this.groupBox1.Name = "groupBox1";

this.groupBox1.Size = new System.Drawing.Size(403, 194);


this.groupBox1.TabIndex = 33;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "PERSONAL DETAILS";
this.groupBox1.Enter += new
System.EventHandler(this.groupBox1_Enter);
//
// groupBox2
//
this.groupBox2.Controls.Add(this.label6);
this.groupBox2.Controls.Add(this.label7);
this.groupBox2.Controls.Add(this.label14);
this.groupBox2.Controls.Add(this.textBox4);
this.groupBox2.Controls.Add(this.textBox5);
this.groupBox2.Controls.Add(this.textBox9);
this.groupBox2.Controls.Add(this.textBox8);
this.groupBox2.Controls.Add(this.listBox3);
this.groupBox2.Controls.Add(this.label9);
this.groupBox2.Controls.Add(this.label10);
this.groupBox2.Controls.Add(this.label8);
this.groupBox2.Controls.Add(this.listBox1);
this.groupBox2.Controls.Add(this.listBox2);
this.groupBox2.Controls.Add(this.textBox7);
this.groupBox2.Controls.Add(this.textBox6);
this.groupBox2.Location = new System.Drawing.Point(117, 224);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(450, 192);
this.groupBox2.TabIndex = 34;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "EDUCATIONAL QUALIFICATION";
this.groupBox2.Enter += new
System.EventHandler(this.groupBox2_Enter);
//
// radioButton1
//
this.radioButton1.AutoSize = true;
this.radioButton1.Location = new System.Drawing.Point(83, 36);
this.radioButton1.Name = "radioButton1";
this.radioButton1.Size = new System.Drawing.Size(71, 17);
this.radioButton1.TabIndex = 35;
this.radioButton1.TabStop = true;
this.radioButton1.Text = "Prize won";
this.radioButton1.UseVisualStyleBackColor = true;
this.radioButton1.CheckedChanged += new
System.EventHandler(this.radioButton1_CheckedChanged);
//
// radioButton2
//
this.radioButton2.AutoSize = true;
this.radioButton2.Location = new System.Drawing.Point(85, 67);
this.radioButton2.Name = "radioButton2";
this.radioButton2.Size = new System.Drawing.Size(71, 17);
this.radioButton2.TabIndex = 36;
this.radioButton2.TabStop = true;
this.radioButton2.Text = "Prize won";
this.radioButton2.UseVisualStyleBackColor = true;
this.radioButton2.CheckedChanged += new
System.EventHandler(this.radioButton2_CheckedChanged);
//
// radioButton3

//
this.radioButton3.AutoSize = true;
this.radioButton3.Location = new System.Drawing.Point(166, 36);
this.radioButton3.Name = "radioButton3";
this.radioButton3.Size = new System.Drawing.Size(83, 17);
this.radioButton3.TabIndex = 37;
this.radioButton3.TabStop = true;
this.radioButton3.Text = "Participation";
this.radioButton3.UseVisualStyleBackColor = true;
this.radioButton3.CheckedChanged += new
System.EventHandler(this.radioButton3_CheckedChanged);
//
// radioButton4
//
this.radioButton4.AutoSize = true;
this.radioButton4.Location = new System.Drawing.Point(166, 67);
this.radioButton4.Name = "radioButton4";
this.radioButton4.Size = new System.Drawing.Size(83, 17);
this.radioButton4.TabIndex = 38;
this.radioButton4.TabStop = true;
this.radioButton4.Text = "Participation";
this.radioButton4.UseVisualStyleBackColor = true;
this.radioButton4.CheckedChanged += new
System.EventHandler(this.radioButton4_CheckedChanged);
//
// groupBox3
//
this.groupBox3.Controls.Add(this.label12);
this.groupBox3.Controls.Add(this.radioButton4);
this.groupBox3.Controls.Add(this.label13);
this.groupBox3.Controls.Add(this.radioButton3);
this.groupBox3.Controls.Add(this.radioButton1);
this.groupBox3.Controls.Add(this.radioButton2);
this.groupBox3.Location = new System.Drawing.Point(117, 435);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(450, 100);
this.groupBox3.TabIndex = 39;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "EXTRA CURRICULAR ACTIVITIES";
this.groupBox3.Enter += new
System.EventHandler(this.groupBox3_Enter);
//
// button1
//
this.button1.Location = new System.Drawing.Point(117, 560);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 40;
this.button1.Text = "SUBMIT";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new
System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(249, 561);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 23);
this.button2.TabIndex = 41;
this.button2.Text = "RESET";

this.button2.TextAlign = System.Drawing.ContentAlignment.TopLeft;
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new
System.EventHandler(this.button2_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(592, 615);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.groupBox3);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout();
this.groupBox3.ResumeLayout(false);
this.groupBox3.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private
private
private
private
private
private
private
private
private
private
private
private
private
private
private
private
private
private
private
private
private
private
private
private
private
private
private
private
private
private

System.Windows.Forms.Label label1;
System.Windows.Forms.Label label2;
System.Windows.Forms.Label label3;
System.Windows.Forms.TextBox textBox1;
System.Windows.Forms.TextBox textBox2;
System.Windows.Forms.CheckBox checkBox1;
System.Windows.Forms.CheckBox checkBox2;
System.Windows.Forms.Label label4;
System.Windows.Forms.TextBox textBox3;
System.Windows.Forms.Label label6;
System.Windows.Forms.Label label7;
System.Windows.Forms.Label label8;
System.Windows.Forms.Label label9;
System.Windows.Forms.Label label10;
System.Windows.Forms.TextBox textBox4;
System.Windows.Forms.TextBox textBox5;
System.Windows.Forms.TextBox textBox6;
System.Windows.Forms.TextBox textBox7;
System.Windows.Forms.Label label12;
System.Windows.Forms.Label label13;
System.Windows.Forms.Label label14;
System.Windows.Forms.TextBox textBox8;
System.Windows.Forms.ListBox listBox1;
System.Windows.Forms.ListBox listBox2;
System.Windows.Forms.ListBox listBox3;
System.Windows.Forms.TextBox textBox9;
System.Windows.Forms.GroupBox groupBox1;
System.Windows.Forms.GroupBox groupBox2;
System.Windows.Forms.RadioButton radioButton1;
System.Windows.Forms.RadioButton radioButton2;

private
private
private
private
private

System.Windows.Forms.RadioButton radioButton3;
System.Windows.Forms.RadioButton radioButton4;
System.Windows.Forms.GroupBox groupBox3;
System.Windows.Forms.Button button1;
System.Windows.Forms.Button button2;

}
}
Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace shvi
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
OleDbConnection Submit = new
OleDbConnection("Provider=Microsoft.JET.oledb.4.0; data source =
db1.mdb");
String i = "insert into Table1 values('" + textBox1.Text + "','"
+ textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text +
"','" + textBox5.Text + "','" + textBox6.Text + "','" +
textBox7.Text + "','" + textBox8.Text + "','" + textBox9.Text +
"','" + textBox10.Text + "')";
OleDbCommand n = new OleDbCommand(i,Submit);
Submit.Open();
n.ExecuteNonQuery();
Submit.Close();
MessageBox.Show("Details submitted");
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
textBox5.Clear();
textBox6.Clear();
textBox7.Clear();
textBox8.Clear();
textBox9.Clear();
textBox10.Clear();
comboBox2.Text = "";
MessageBox.Show("All fields are cleared");
}

private void comboBox1_SelectedIndexChanged(object sender, EventArgs

e)

{
}
private void groupBox3_Enter(object sender, EventArgs e)
{
}
private void label7_Click(object sender, EventArgs e)
{
}
private void label9_Click(object sender, EventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
OleDbConnection Submit = new
OleDbConnection("Provider=Microsoft.JET.oledb.4.0; data source =
db1.mdb");
String up = "update Table set name='" + textBox1.Text + "', where
age='20'";
OleDbCommand n = new OleDbCommand(up,Submit);
Submit.Open();
n.ExecuteNonQuery();
Submit.Close();
}
private void button4_Click(object sender, EventArgs e)
{
OleDbConnection Submit = new
OleDbConnection("Provider=Microsoft.JET.oledb.4.0; data source =
db1.mdb");
String del = "delete name from Table where name='vijay'";
OleDbCommand n = new OleDbCommand(del, Submit);
Submit.Open();
n.ExecuteNonQuery();
Submit.Close();
}
}

Output

Database

Result
Thus a windows form for resume submission through online mode is successfully executed.

8. Write a C# program to insert students academic and personal details into a Oracle/SQL Server
database and to retrieve the student details from the database for a given condition and populate
the same in a data-grid control
Aim
To write a c# program to insert student personal and academic details and to retrieve the database
information upon condition and populating in data-grid control.
Algorithm
1. Start the program
2. Create a windows application
3. Select add existing item in project menu and add the sql database.
4. Create table and insert values into it.
5. Create interface as follows

6. Include function for the buttons.


7. Display the result.
8. Stop the program
Program
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Final
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();

}
System.Data.SqlClient.SqlConnection con;
System.Data.SqlClient.SqlDataAdapter da;
DataSet ds1;
int MaxRows = 0;
int inc = 0;
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'studentDataSet4.student' table. You can move, or
remove it, as needed.
this.studentTableAdapter1.Fill(this.studentDataSet4.student);
// TODO: This line of code loads data into the 'studentDataSet2.student' table. You can move, or
remove it, as needed.
this.studentTableAdapter.Fill(this.studentDataSet2.student);
// TODO: This line of code loads data into the 'myWorkersDataSet2.tblworkers' table. You can
move, or remove it, as needed.
con = new System.Data.SqlClient.SqlConnection();
ds1 = new DataSet();
con.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|
DataDirectory|\\student.mdf;Integrated Security=True;User Instance=True";
string sql = "SELECT * From student";
da = new System.Data.SqlClient.SqlDataAdapter(sql, con);
con.Open();
da.Fill(ds1, "student");
NavigateRecords();
MaxRows = ds1.Tables["student"].Rows.Count;
con.Close();
// con.Dispose();
Console.ReadLine()
}
private void NavigateRecords()
{
DataRow dRow = ds1.Tables["student"].Rows[inc];
textBox1.Text = dRow.ItemArray.GetValue(0).ToString();
textBox2.Text = dRow.ItemArray.GetValue(1).ToString();
textBox3.Text = dRow.ItemArray.GetValue(2).ToString();
textBox4.Text = dRow.ItemArray.GetValue(3).ToString();
textBox5.Text = dRow.ItemArray.GetValue(4).ToString();
}
private void button1_Click(object sender, EventArgs e)
{
if (inc != MaxRows - 1)
{
inc++;
NavigateRecords();
}
else
{
MessageBox.Show("No more records");
}
}

private void button2_Click(object sender, EventArgs e)


{
if (inc > 0)
{
inc--;
NavigateRecords();
}
else
{
MessageBox.Show("First Record");
}
}
private void button4_Click(object sender, EventArgs e)
{
if (inc != MaxRows - 1)
{
inc = MaxRows - 1;
NavigateRecords();
}
}
private void button3_Click(object sender, EventArgs e)
{
if (inc != 0)
{
inc = 0;
NavigateRecords();
}
}
private void button5_Click(object sender, EventArgs e)
{
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
textBox5.Clear();
}
private void button6_Click(object sender, EventArgs e)
{
string searchFor = textBox1.Text;
int results = 0;
DataRow[] returnedRows;
returnedRows = ds1.Tables["student"].Select("Name='" + searchFor + "'");
results = returnedRows.Length;
if (results > 0)
{
DataRow drl;
drl = returnedRows[0];
textBox1.Text = drl["Name"].ToString() ;
textBox2.Text = drl["Age"].ToString();

textBox3.Text = drl["Sex"].ToString();
textBox4.Text = drl["10th percent"].ToString();
textBox5.Text = drl["12th percent"].ToString();
}
else
{
MessageBox.Show("No such record");
}
}
private void button7_Click(object sender, EventArgs e)
{
System.Data.SqlClient.SqlCommandBuilder cb;
cb = new System.Data.SqlClient.SqlCommandBuilder(da);
DataRow dRow = ds1.Tables["student"].NewRow();
dRow[0] = textBox1.Text;
dRow[1] = textBox2.Text;
dRow[2] = textBox3.Text;
dRow[3] = textBox4.Text;
dRow[4] = textBox5.Text;
ds1.Tables["student"].Rows.Add(dRow);
MaxRows = MaxRows + 1;
inc = MaxRows - 1;
da.Update(ds1, "student");
MessageBox.Show("Entry added");
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
System.Data.SqlClient.SqlCommandBuilder cb;
cb = new System.Data.SqlClient.SqlCommandBuilder(da);
DataRow dRow = ds1.Tables["student"].NewRow();
dRow[0] = textBox1.Text;
dRow[1] = textBox2.Text;
dRow[2] = textBox3.Text;
dRow[3] = textBox4.Text;
dRow[4] = textBox5.Text;
ds1.Tables["student"].Rows.Add(dRow);
MaxRows = MaxRows + 1;
inc = MaxRows - 1;
da.Update(ds1, "student");
MessageBox.Show("Entry added");
}
}
}

Output

Result
Thus a c# program to insert student personal and academic details and to retrieve the database
information upon condition and populating in data-grid control was successfully executed.

9. Create a Calculator web service in ASP.NET with arithmetic & trigonometric operations and
write an appropriate client code to access the calculator web service.
Aim
To create a calculator web service in ASP.NET with arithmetic and trigonometric operation and
also to create client access to the web service
Algorithm
1. Start the program
2. Create a new ASP.NET web service application with C# language option
3. Create the functions for arithmetic and trigonometric functions
4. Compile and run the program
5. Upon the successful execution of the program on server side, create program to access the
functions on client side using the wsdl tool
6. Create a c# console application on client side that creates a proxy and calls the server side defined
functions
7. Display the result
8. Stop the program
Program
Server side program:
using
using
using
using

System;
System.Web;
System.Web.Services;
System.Web.Services.Protocols;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//[WebServiceBinding(ConformsTo = WsiProfiles.bp10,EmitConformanceClaims =
true)]
//.BP10,EmitConformanceClaims = true)]
public class Service : System.Web.Services.WebService
{
public Service()
{
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
[WebMethod]
public double add(double x, double y)
{
return x + y;
}
[WebMethod]
public double sub(double x, double y)
{
return x - y;
}
[WebMethod]
public double mul(double x, double y)
{
return x * y;
}
[WebMethod]

public double div(double x, double y)


{
return x / y;
}
[WebMethod]
public double pow(double x, double y)
{
double retval = x;
for (int i = 0; i < y - 1; i++)
{
retval *= x;
}
return retval;
}
[WebMethod]
public double sin(double num)
{
return Math.Sin(num);
}
[WebMethod]
public double cos(double num)
{
return Math.Cos(num);
}
[WebMethod]
public double tan(double num)
{
return Math.Tan(num);
}

Client side program generated using wsdl tool


//----------------------------------------------------------------------------// <auto-generated>
//
This code was generated by a tool.
//
Runtime Version:2.0.50727.4927
//
//
Changes to this file may cause incorrect behavior and will be lost if
//
the code is regenerated.
// </auto-generated>
//----------------------------------------------------------------------------using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Serialization;
//
// This source code was auto-generated by wsdl, Version=2.0.50727.42.
//
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Web.Services.WebServiceBindingAttribute(Name="ServiceSoap",
Namespace="http://tempuri.org/")]
public partial class Service :
System.Web.Services.Protocols.SoapHttpClientProtocol {
private System.Threading.SendOrPostCallback HelloWorldOperationCompleted;

private System.Threading.SendOrPostCallback addOperationCompleted;


private System.Threading.SendOrPostCallback subOperationCompleted;
private System.Threading.SendOrPostCallback mulOperationCompleted;
private System.Threading.SendOrPostCallback divOperationCompleted;
private System.Threading.SendOrPostCallback powOperationCompleted;
/// <remarks/>
public Service() {
this.Url = "http://localhost:49621/WebSite1/Service.asmx";
}
/// <remarks/>
public event HelloWorldCompletedEventHandler HelloWorldCompleted;
/// <remarks/>
public event addCompletedEventHandler addCompleted;
/// <remarks/>
public event subCompletedEventHandler subCompleted;
/// <remarks/>
public event mulCompletedEventHandler mulCompleted;
/// <remarks/>
public event divCompletedEventHandler divCompleted;
/// <remarks/>
public event powCompletedEventHandler powCompleted;
/// <remarks/>
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.or
g/HelloWorld", RequestNamespace="http://tempuri.org/",
ResponseNamespace="http://tempuri.org/",
Use=System.Web.Services.Description.SoapBindingUse.Literal,
ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public string HelloWorld() {
object[] results = this.Invoke("HelloWorld", new object[0]);
return ((string)(results[0]));
}
/// <remarks/>
public System.IAsyncResult BeginHelloWorld(System.AsyncCallback callback,
object asyncState) {
return this.BeginInvoke("HelloWorld", new object[0], callback,
asyncState);
}
/// <remarks/>
public string EndHelloWorld(System.IAsyncResult asyncResult) {
object[] results = this.EndInvoke(asyncResult);
return ((string)(results[0]));
}
/// <remarks/>
public void HelloWorldAsync() {
this.HelloWorldAsync(null);
}
/// <remarks/>
public void HelloWorldAsync(object userState) {
if ((this.HelloWorldOperationCompleted == null)) {
this.HelloWorldOperationCompleted = new
System.Threading.SendOrPostCallback(this.OnHelloWorldOperationCompleted);
}
this.InvokeAsync("HelloWorld", new object[0],
this.HelloWorldOperationCompleted, userState);
}
private void OnHelloWorldOperationCompleted(object arg) {
if ((this.HelloWorldCompleted != null)) {
System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs
= ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));

this.HelloWorldCompleted(this, new
HelloWorldCompletedEventArgs(invokeArgs.Results, invokeArgs.Error,
invokeArgs.Cancelled, invokeArgs.UserState));
}
}
/// <remarks/>
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.or
g/add", RequestNamespace="http://tempuri.org/",
ResponseNamespace="http://tempuri.org/",
Use=System.Web.Services.Description.SoapBindingUse.Literal,
ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public double add(double x, double y) {
object[] results = this.Invoke("add", new object[] {
x,
y});
return ((double)(results[0]));
}
/// <remarks/>
public System.IAsyncResult Beginadd(double x, double y,
System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("add", new object[] {
x,
y}, callback, asyncState);
}
/// <remarks/>
public double Endadd(System.IAsyncResult asyncResult) {
object[] results = this.EndInvoke(asyncResult);
return ((double)(results[0]));
}
/// <remarks/>
public void addAsync(double x, double y) {
this.addAsync(x, y, null);
}
/// <remarks/>
public void addAsync(double x, double y, object userState) {
if ((this.addOperationCompleted == null)) {
this.addOperationCompleted = new
System.Threading.SendOrPostCallback(this.OnaddOperationCompleted);
}
this.InvokeAsync("add", new object[] {
x,
y}, this.addOperationCompleted, userState);
}
private void OnaddOperationCompleted(object arg) {
if ((this.addCompleted != null)) {
System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs
= ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
this.addCompleted(this, new
addCompletedEventArgs(invokeArgs.Results, invokeArgs.Error,
invokeArgs.Cancelled, invokeArgs.UserState));
}
}
/// <remarks/>
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.or
g/sub", RequestNamespace="http://tempuri.org/",
ResponseNamespace="http://tempuri.org/",
Use=System.Web.Services.Description.SoapBindingUse.Literal,
ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public double sub(double x, double y) {
object[] results = this.Invoke("sub", new object[] {

x,
y});
return ((double)(results[0]));

}
/// <remarks/>
public System.IAsyncResult Beginsub(double x, double y,
System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("sub", new object[] {
x,
y}, callback, asyncState);
}
/// <remarks/>
public double Endsub(System.IAsyncResult asyncResult) {
object[] results = this.EndInvoke(asyncResult);
return ((double)(results[0]));
}
/// <remarks/>
public void subAsync(double x, double y) {
this.subAsync(x, y, null);
}
/// <remarks/>
public void subAsync(double x, double y, object userState) {
if ((this.subOperationCompleted == null)) {
this.subOperationCompleted = new
System.Threading.SendOrPostCallback(this.OnsubOperationCompleted);
}
this.InvokeAsync("sub", new object[] {
x,
y}, this.subOperationCompleted, userState);
}
private void OnsubOperationCompleted(object arg) {
if ((this.subCompleted != null)) {
System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs
= ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
this.subCompleted(this, new
subCompletedEventArgs(invokeArgs.Results, invokeArgs.Error,
invokeArgs.Cancelled, invokeArgs.UserState));
}
}
/// <remarks/>
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.or
g/mul", RequestNamespace="http://tempuri.org/",
ResponseNamespace="http://tempuri.org/",
Use=System.Web.Services.Description.SoapBindingUse.Literal,
ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public double mul(double x, double y) {
object[] results = this.Invoke("mul", new object[] {
x,
y});
return ((double)(results[0]));
}
/// <remarks/>
public System.IAsyncResult Beginmul(double x, double y,
System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("mul", new object[] {
x,
y}, callback, asyncState);
}
/// <remarks/>

public double Endmul(System.IAsyncResult asyncResult) {


object[] results = this.EndInvoke(asyncResult);
return ((double)(results[0]));
}
/// <remarks/>
public void mulAsync(double x, double y) {
this.mulAsync(x, y, null);
}
/// <remarks/>
public void mulAsync(double x, double y, object userState) {
if ((this.mulOperationCompleted == null)) {
this.mulOperationCompleted = new
System.Threading.SendOrPostCallback(this.OnmulOperationCompleted);
}
this.InvokeAsync("mul", new object[] {
x,
y}, this.mulOperationCompleted, userState);
}
private void OnmulOperationCompleted(object arg) {
if ((this.mulCompleted != null)) {
System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs
= ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
this.mulCompleted(this, new
mulCompletedEventArgs(invokeArgs.Results, invokeArgs.Error,
invokeArgs.Cancelled, invokeArgs.UserState));
}
}
/// <remarks/>
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.or
g/div", RequestNamespace="http://tempuri.org/",
ResponseNamespace="http://tempuri.org/",
Use=System.Web.Services.Description.SoapBindingUse.Literal,
ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public double div(double x, double y) {
object[] results = this.Invoke("div", new object[] {
x,
y});
return ((double)(results[0]));
}
/// <remarks/>
public System.IAsyncResult Begindiv(double x, double y,
System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("div", new object[] {
x,
y}, callback, asyncState);
}
/// <remarks/>
public double Enddiv(System.IAsyncResult asyncResult) {
object[] results = this.EndInvoke(asyncResult);
return ((double)(results[0]));
}
/// <remarks/>
public void divAsync(double x, double y) {
this.divAsync(x, y, null);
}
/// <remarks/>
public void divAsync(double x, double y, object userState) {
if ((this.divOperationCompleted == null)) {
this.divOperationCompleted = new
System.Threading.SendOrPostCallback(this.OndivOperationCompleted);

}
this.InvokeAsync("div", new object[] {
x,
y}, this.divOperationCompleted, userState);
}
private void OndivOperationCompleted(object arg) {
if ((this.divCompleted != null)) {
System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs
= ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
this.divCompleted(this, new
divCompletedEventArgs(invokeArgs.Results, invokeArgs.Error,
invokeArgs.Cancelled, invokeArgs.UserState));
}
}
/// <remarks/>
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.or
g/pow", RequestNamespace="http://tempuri.org/",
ResponseNamespace="http://tempuri.org/",
Use=System.Web.Services.Description.SoapBindingUse.Literal,
ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public double pow(double x, double y) {
object[] results = this.Invoke("pow", new object[] {
x,
y});
return ((double)(results[0]));
}
/// <remarks/>
public System.IAsyncResult Beginpow(double x, double y,
System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("pow", new object[] {
x,
y}, callback, asyncState);
}
/// <remarks/>
public double Endpow(System.IAsyncResult asyncResult) {
object[] results = this.EndInvoke(asyncResult);
return ((double)(results[0]));
}
/// <remarks/>
public void powAsync(double x, double y) {
this.powAsync(x, y, null);
}
/// <remarks/>
public void powAsync(double x, double y, object userState) {
if ((this.powOperationCompleted == null)) {
this.powOperationCompleted = new
System.Threading.SendOrPostCallback(this.OnpowOperationCompleted);
}
this.InvokeAsync("pow", new object[] {
x,
y}, this.powOperationCompleted, userState);
}
private void OnpowOperationCompleted(object arg) {
if ((this.powCompleted != null)) {
System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs
= ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
this.powCompleted(this, new
powCompletedEventArgs(invokeArgs.Results, invokeArgs.Error,
invokeArgs.Cancelled, invokeArgs.UserState));
}

}
/// <remarks/>
public new void CancelAsync(object userState) {
base.CancelAsync(userState);
}

}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
public delegate void HelloWorldCompletedEventHandler(object sender,
HelloWorldCompletedEventArgs e);
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
public partial class HelloWorldCompletedEventArgs :
System.ComponentModel.AsyncCompletedEventArgs {
private object[] results;
internal HelloWorldCompletedEventArgs(object[] results, System.Exception
exception, bool cancelled, object userState) :
base(exception, cancelled, userState) {
this.results = results;
}
/// <remarks/>
public string Result {
get {
this.RaiseExceptionIfNecessary();
return ((string)(this.results[0]));
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
public delegate void addCompletedEventHandler(object sender,
addCompletedEventArgs e);
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
public partial class addCompletedEventArgs :
System.ComponentModel.AsyncCompletedEventArgs {
private object[] results;
internal addCompletedEventArgs(object[] results, System.Exception
exception, bool cancelled, object userState) :
base(exception, cancelled, userState) {
this.results = results;
}
/// <remarks/>
public double Result {
get {
this.RaiseExceptionIfNecessary();
return ((double)(this.results[0]));
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
public delegate void subCompletedEventHandler(object sender,
subCompletedEventArgs e);
/// <remarks/>

[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
public partial class subCompletedEventArgs :
System.ComponentModel.AsyncCompletedEventArgs {
private object[] results;
internal subCompletedEventArgs(object[] results, System.Exception
exception, bool cancelled, object userState) :
base(exception, cancelled, userState) {
this.results = results;
}
/// <remarks/>
public double Result {
get {
this.RaiseExceptionIfNecessary();
return ((double)(this.results[0]));
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
public delegate void mulCompletedEventHandler(object sender,
mulCompletedEventArgs e);
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
public partial class mulCompletedEventArgs :
System.ComponentModel.AsyncCompletedEventArgs {
private object[] results;
internal mulCompletedEventArgs(object[] results, System.Exception
exception, bool cancelled, object userState) :
base(exception, cancelled, userState) {
this.results = results;
}
/// <remarks/>
public double Result {
get {
this.RaiseExceptionIfNecessary();
return ((double)(this.results[0]));
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
public delegate void divCompletedEventHandler(object sender,
divCompletedEventArgs e);
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
public partial class divCompletedEventArgs :
System.ComponentModel.AsyncCompletedEventArgs {
private object[] results;
internal divCompletedEventArgs(object[] results, System.Exception
exception, bool cancelled, object userState) :
base(exception, cancelled, userState) {
this.results = results;
}
/// <remarks/>

public double Result {


get {
this.RaiseExceptionIfNecessary();
return ((double)(this.results[0]));
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
public delegate void powCompletedEventHandler(object sender,
powCompletedEventArgs e);
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
public partial class powCompletedEventArgs :
System.ComponentModel.AsyncCompletedEventArgs {
private object[] results;
internal powCompletedEventArgs(object[] results, System.Exception
exception, bool cancelled, object userState) :
base(exception, cancelled, userState) {
this.results = results;
}
/// <remarks/>
public double Result {
get {
this.RaiseExceptionIfNecessary();
return ((double)(this.results[0]));
}
}
}

Client side program that calls server function using proxy


#region Using directives
using System;
using System.Collections.Generic;
using System.Text;
#endregion
namespace calci
{
class Program
{
public class tester
{
public void run()
{
int var1 = 10;
int var2 = 5;
int n = 5;
Service theWebSvc = new Service();
Console.WriteLine("Arithmetic operations:");
Console.WriteLine("Add: " + theWebSvc.add(var1,var2));
Console.WriteLine("Sub: " + theWebSvc.sub(var1, var2));
Console.WriteLine("Mul: " + theWebSvc.mul(var1, var2));
Console.WriteLine("Div: " + theWebSvc.div(var1, var2));
Console.WriteLine("Trigonometric funtions");
Console.WriteLine("Sin : " + theWebSvc.sin(n));
Console.WriteLine("Cos : " + theWebSvc.cos(n));
Console.WriteLine("Tan: " + theWebSvc.tan(n));
}
public static void Main()

}
}
}

Output
Server side

tester t = new tester();


t.run();
Console.ReadLine();

Client side

Result
Thus a calculator web service using ASP.NET for both server-side and client-side was
successfully executed.

10. Write a C# program to build a multi module and shared assembly.


Aim
To write a C# program to build a multi module and shared assembly.
Algorithm
1. Start the program
2. Create four different with a class that creates object to the rest of the three classes
3. Compile the classes using the csc compiler as follows
DotNet> csc /debug /t:module /out:bin\Hello.dll Hello.cs
DotNet> csc /debug /t:module /out:bin\GoodBye.dll GoodBye.cs
DotNet> csc /debug /t:module /out:bin\HowDoYouDo.dll HowDoYouDo.cs

4. Create the Private Assembly GreetAssembly.dll from Hello.dll and GoodBye.dll. The code is
DotNet> al /t:library /out:bin\GreetAssembly.dll bin\Hello.dll bin\GoodBye.dll

5. Create the Global Assembly HowDoYouDoSharedAssembly.dll from HowDoYouDo.dll.


6. Generate the key file for creating a hash key to each file using the code
DotNet> sn -k app.snk

7. Link the DLL with the Assembly Linker (AL) to a Global Assembly incorporating the key file
and version number.
DotNet> al /t:library /out:bin\HowDoYouDoSharedAssembly.dll bin\HowDoYouDo.dll

8. Load the Global Assembly into GAC by the use of the Global Assembly Cache Utility
using the code
gacutil /i bin\HowDoYouDoSharedAssembly.dll

9. Reference Private and Global Assemblies within App1.exe


10. Call DLLs directly and reference Global Assemblies within App2.exe
11. The code for app1 and app2 invoke is
csc /debug /t:exe /r:bin\GreetAssembly.dll;bin\
HowDoYouDoSharedAssembly.dll /out:bin\App1.exe App.cs
csc /debug /t:exe /lib:bin /addmodule:Hello.dll;GoodBye.dll
/r:bin\HowDoYouDoSharedAssembly.dll /out:bin\App2.exe App.cs

12. Display the output.


13. Stop the program.
Program
App.cs

using csharp.test.app.greet;
namespace csharp.test.app
{
public class Application
{
public static void Main()
{
Application a = new Application();
Hello h = new Hello();
h.SayHello();
HowDoYouDo d = new HowDoYouDo();
d.SayHowDoYouDo();
a.Leave();
}
private void Leave()
{
GoodBye g = new GoodBye();
g.SayGoodBye();
}

Hello.cs

namespace csharp.test.app.greet
{
public class Hello
{
public void SayHello()
{
System.Console.WriteLine("Hello my friend, I am a DLL");
}
}
}
GoodBye.cs

namespace csharp.test.app.greet
{
public class GoodBye
{
public void SayGoodBye()
{
System.Console.WriteLine("Good bye, I am a DLL too");
}
}
}
HowDoYouDo.cs

using System.Reflection;
[assembly: AssemblyKeyFile("app.snk")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace csharp.test.app
{
public class HowDoYouDo
{
public void SayHowDoYouDo()
{
System.Console.WriteLine("How do you do, I am a Global
Assembly");
}
}
}

Output

Result
Thus a C# program for building a multi module and shared assembly is successfully executed.

11. Write a C# program to invoke a method dynamically which resides in a remote machine and
also perform the required marshaling and un marshaling on the arguments passing to a remote
method.
Aim
To write a c# program that performs marshaling and un marshaling by invoking a method
dynamically with help of parameter passing
Algorithm
1. Start the program
2. Create a new windows console application
3. Create a class
4. Invoke a method dynamically that resides on a remote machine
5. Perform marshaling and un marshaling
6. Pass the parameters to the invoked method
7. Display the output
8. Stop the program
Program
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace ConsoleApplication5
{
class Program
{
public struct Point
{
public Int32 x, y;
}
public sealed class App
{
static void Main()
{
Console.WriteLine("SystemDefaultCharSize={0},
SystemMaxDBCSCharSize={1}",
Marshal.SystemDefaultCharSize, Marshal.SystemMaxDBCSCharSize);
Console.WriteLine("Number of bytes needed by a Point object:
{0}",
Marshal.SizeOf(typeof(Point)));
Point p = new Point();
Console.WriteLine("Number of bytes needed by a Point object:
{0}",
Marshal.SizeOf(p));
// Demonstrate how to call GlobalAlloc and
// GlobalFree using the Marshal class.
IntPtr hglobal = Marshal.AllocHGlobal(100);
Marshal.FreeHGlobal(hglobal);
// Demonstrate how to use the Marshal class to get the Win32
error
// code when a Win32 method fails.
Boolean f = CloseHandle(new IntPtr(-1));
if (!f)
{
Console.WriteLine("CloseHandle call failed with an error code of:
{0}",
Marshal.GetLastWin32Error());

}
Console.ReadLine();
}
// This is a platform invoke prototype. SetLastError is true,
which allows
// the GetLastWin32Error method of the Marshal class to work
correctly.
[DllImport("Kernel32", ExactSpelling = true, SetLastError =
true)]
static extern Boolean CloseHandle(IntPtr h);
}

Output

Result
Thus a C# program that performs marshaling and un marshaling by invoking a method on remote
machine is successfully executed.

12. Write a C# program to implement the producer - consumer problem by using threads and
thread synchronization.
Aim
To write a C# program to implement the producer consumer problem using threads and thread
synchronization.
Algorithm
1. Start the program
2. Include the necessary header files.
3. Create classes for producer and consumer.
4. Define the produce and consume function in the respective classes.
5. Inside the main class, create objects for the producer and consumer class and invoke its functions.
6. Display the result.
7. Stop the program.
Program
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
namespace producer
{
class Program
{
public class Producer
{
Queue<string> queue;
static int seq;
public Producer(Queue<string> queue)
{
this.queue = queue;
}
public void produce()
{
while (seq++ < 10)
{
string item = "item" + seq;
queue.Enqueue(item);
Console.WriteLine("Producing {0}", item);
}
}
}
public class Comsumer
{
Queue<string> queue;
Object lockObject;
string name;
public Comsumer(Queue<string> queue, Object lockObject, string
name)
{
this.queue = queue;
this.lockObject = lockObject;
this.name = name;
}
public void consume()
{
string item;
while (true)

lock (lockObject)
{
if (queue.Count == 0)
{
continue;
}
Thread.Sleep(5);
item = queue.Dequeue();
Console.WriteLine(" {0} Comsuming {1}", name, item);
}

}
{

}
}
}

Output

static void Main()


Object lockObj = new object();
Queue<string> queue = new Queue<string>();
Producer p = new Producer(queue);
Comsumer c1 = new Comsumer(queue, lockObj, "c1");
Comsumer c2 = new Comsumer(queue, lockObj, "c2");
Thread t1 = new Thread(c1.consume);
Thread t2 = new Thread(c2.consume);
t1.Start();
t2.Start();
Thread t = new Thread(p.produce);
t.Start();
Console.ReadLine();
}

Result
Thus a C# program for implementing producer consumer problem using thread and thread
synchronization was successfully executed.

EXPERIMENTS BEYOND SYLLABUS


1.Method overloading
Program:
using System;
using System.Drawing;
class TestBaseCarClass
{
static void Main()
{
Console.WriteLine(Add(1, 1));
}
static int Add(int a, int b)
{
return Add(a, b, 0, 0);
}
static int Add(int a, int b, int c)
{
return Add(a, b, c, 0);
}
static int Add(int a, int b, int c, int d)
{
return a + b + c + d;
}
}
Output:
2
3
4
2.File operations
Program
//Write a binary file
public class WriteFileBinary
{
public WriteFileBinary()
{
string name;
int[] scores = new int[3];
Console.WriteLine("Enter file name :");
name = Console.ReadLine();
for (int i = 0; i < 3; i++)
{
Console.WriteLine("Content ", i + 1);
scores[i] = Convert.ToInt32(Console.ReadLine());
}
FileStream myFile = new FileStream("hello.bin", FileMode.Create);
BinaryWriter filedata = new BinaryWriter(myFile);

filedata.Write(name);
for (int i = 0; i < 3; i++)
{
filedata.Write(scores[i]);
}
filedata.Close();
myFile.Close();
}
}
//Read a binary file
public class ReadFileBinary
{
public ReadFileBinary()
{
string name;
int[] scores = new int[3];
FileStream myFile = new FileStream("hello.bin", FileMode.Open);
BinaryReader filedata = new BinaryReader(myFile);
name = filedata.ReadString();
for (int i = 0; i < 3; i++)
{
scores[i] = filedata.ReadInt32();
}
filedata.Close();
myFile.Close();
Console.WriteLine("Information from file");
Console.WriteLine("Name {0} :", name);
for (int i = 0; i < 3; i++)
{
Console.WriteLine("", i + 1, scores[i]);
}
}
}
Output:
Enter file name
Content
Hi welcome
Information from file
Hi welcome

Вам также может понравиться