NET FRAMEWORK
LAB MANUAL
LIST OF EXPERIMENTS
SOFTWARES REQUIRED
LANGUAGES
C#
EXERCISE 1.
using
using
using
using
PASS BY VALUE
System;
System.Collections.Generic;
System.Linq;
System.Text;
namespace exercise1
{
class passbyvalue
{
static void change(int m)
{
m = m + 10;
}
static void Main(string[] args)
{
int x = 100;
change(x);
Console.WriteLine("x=" + x);
Console.Read();
}
}
}
Output
1.b)PASS BY REFERRENCE
3
using
using
using
using
System;
System.Collections.Generic;
System.Linq;
System.Text;
namespace exercise1b
{
class passbyref
{
static void swap(ref int x, ref int y)
{
int temp = x;
x = y;
y = temp;
}
static void Main(string[] args)
{
int m = 100;
int n = 200;
Console.WriteLine("before swapping");
Console.WriteLine("m=" + m);
Console.WriteLine("n=" + n);
swap(ref m,ref n);
Console.WriteLine("afterswapping");
Console.WriteLine("m=" + m);
Console.WriteLine("n=" + n);
Console.Read();
}
}
}
Output
1.c)OUT PARAMETER
4
using System.Text;
namespace exercise1c
{
class outkey
{
static void square(int x,out int y)
{
y = x * x;
}
static void Main(string[] args)
{
int m;
square(10, out m);
int n = 200;
Console.WriteLine("m=" + m);
Console.Read();
}
}
Output
1.d)PARAMS KEYWORD
5
using System.Text;
namespace exercise1c
{
class paramkey
{
static void parray(params int []arr)
{
Console.Write("array elements are");
foreach (int i in arr)
Console.Write(" " + i);
Console.WriteLine();
}
static void Main(string[] args)
{
int []x={11,22,33};
parray(x);//call 1
parray();//call 2
parray(100, 200);//call 3
Console.Read();
}
}
}
Output
EXERCISE:
using System;
using System.Collections.Generic;
using System.Linq;
using System;
namespace tutorialspoint
{
class Student
{
private string code = "N.A";
private string name = "not known";
private int age = 0;
// Declare a Code property of type string:
public string Code
{
get
{
return code;
}
set
{
code = value;
}
}
// Declare a Name property of type string:
public string Name
{
get
{
return name;
}
set
{
name = value;
}
}
class ExampleDemo
{
public static void Main()
{
// Create a new Student object:
Student s = new Student();
}
}
Output
EXERCISE:3.
using
using
using
using
System;
System.Collections.Generic;
System.Linq;
System.Text;
namespace BAppl
{
class Account
{
protected string firstName;
protected string lastName;
protected long number;
// protected decimal initialBalance;
public string FirstName
{
set
{
firstName = value;
}
}
public string LastName
{
set
{
lastName = value;
}
}
public long Number
{
set
{
number = value;
}
}
/*
public decimal Initial
{
set
{
initialBalance = value;
}
}*/
public override string ToString()
{
return firstName + " " + lastName + "\nAccount #: " + number ;
}
}
//Checking Account Class:
class CheckingAccount : Account
{
{
}
set
{
}
return balance;
balance = value;
//Display class:
class Display
{
Console.WriteLine("**********************");
Console.WriteLine("After Depositing Rs.6000.");
check.deposit(6000);
check.display();
//constructor
Console.WriteLine("**********************");
Console.WriteLine("After Withdrawing Rs.2000...");
check.withdraw(2000);
check.display();
//constructor
Console.Read();
}
}
Output
10
EXERCISE:4.
using System;
using System.Collections.Generic;
11
using System.Linq;
using System.Text;
namespace InterfaceApplication
{
public interface ITransactions
{
// interface members
void showTransaction();
double getAmount();
}
public class Transaction : ITransactions
{
private string tCode;
private string date;
private double amount;
public Transaction()
{
tCode = " ";
date = " ";
amount = 0.0;
}
public Transaction(string c, string d, double a)
{
tCode = c;
date = d;
amount = a;
}
public double getAmount()
{
return amount;
}
public void showTransaction()
{
Console.WriteLine("Transaction: {0}", tCode);
Console.WriteLine("Date: {0}", date);
Console.WriteLine("Amount: {0}", getAmount());
}
}
class Tester
{
static void Main(string[] args)
{
Transaction t1 = new Transaction("001", "8/10/2012", 78900.00);
Transaction t2 = new Transaction("002", "9/10/2012", 451900.00);
t1.showTransaction();
t2.showTransaction();
Console.ReadKey();
}
}
}
output
12
EXERCISE:5.
using System;
using System.Collections.Generic;
13
using System.Linq;
using System.Text;
using System.Collections;
namespace stackexpression
{
class eva
{
public string po;
public string answer;
Stack i = new Stack();
public void e()
{
int a, b, ans;
for (int j = 0; j < po.Length; j++)
{
String c = po.Substring(j, 1);
if (c.Equals ("*"))
{
String sa = (String)i.Pop();
String sb = (String)i.Pop();
a = Convert.ToInt32(sb);
b = Convert.ToInt32(sa);
ans = a * b;
i.Push(ans.ToString());
}
else if (c.Equals("/"))
{
String sa = (String)i.Pop();
String sb = (String)i.Pop();
a = Convert.ToInt32(sb);
b = Convert.ToInt32(sa);
ans = a / b;
i.Push(ans.ToString());
}
else if (c.Equals("+"))
{
String sa = (String)i.Pop();
String sb = (String)i.Pop();
a = Convert.ToInt32(sb);
b = Convert.ToInt32(sa);
ans = a + b;
i.Push(ans.ToString());
}
else if (c.Equals("-"))
{
String sa = (String)i.Pop();
String sb = (String)i.Pop();
a = Convert.ToInt32(sb);
b = Convert.ToInt32(sa);
ans = a - b;
i.Push(ans.ToString());
}
else
{
14
i.Push(po.Substring(j, 1));
}
answer=(String)i.Pop();
}
}
class Program
{
static void Main(string[] args)
{
eva e1 = new eva();
Console.WriteLine("enter any po:stfix expression");
e1.po = Console.ReadLine();
e1.e();
Console.WriteLine("\n\t\tpostfix evaluation: " + e1.answer);
Console.ReadKey();
}
}
}
output
EXERCISE:6.
using System;
using System.Collections.Generic;
15
using System.Linq;
using System.Text;
namespace operatoroverloading
{
public struct Complex
{
public int real;
public int imaginary;
// Constructor.
public Complex(int real, int imaginary)
{
this.real = real;
this.imaginary = imaginary;
}
// Specify which operator to overload (+),
// the types that can be added (two Complex objects),
// and the return type (Complex).
public static Complex operator +(Complex c1, Complex c2)
{
return new Complex(c1.real + c2.real, c1.imaginary + c2.imaginary);
}
class TestComplex
{
static void Main()
{
Complex num1 = new Complex(2, 3);
Complex num2 = new Complex(3, 4);
// Add two Complex objects by using the overloaded + operator.
Complex sum = num1 + num2;
// Print the numbers and the sum by using the overridden
// ToString method.
System.Console.WriteLine("First complex number: {0}", num1);
System.Console.WriteLine("Second complex number: {0}", num2);
System.Console.WriteLine("The sum of the two numbers: {0}", sum);
// Keep the console window open in debug mode.
System.Console.WriteLine("Press any key to exit.");
System.Console.ReadKey();
}
Output
16
EXERCISE:7. ADDITION&
using
using
using
using
System;
System.Collections.Generic;
System.Linq;
System.Text;
namespace ConsoleApplication4
{
using System;
delegate int NumberChanger(int n);
namespace example
{
17
class Delegate
{
static int num = 10;
public static int AddNum(int a)
{
num += a;
return num;
}
public static int MultNum(int b)
{
num *= b;
return num;
}
public static int getNum()
{
return num;
}
static void Main(string[] args)
{
}
}
Output
18
EXERCISE:8.
using System;
using
using
using
using
System.Collections.Generic;
System.Linq;
System.Text;
System.Threading;
namespace Events
{
class Program
{
static void Main(string[] args)
{
IQTest objTest = new IQTest(); //Publisher
NotificationService objNotify = new NotificationService();
//Subscriber
// += Register a Handler for that Event
objTest.ExamStarted += objNotify.OnExamStarted;
objTest.myExam();
Console.Read();
}
//Publisher or Sender
class IQTest
{
//Delegate
public delegate void ExamEventHandler(object source, EventArgs args);
//Event
public event ExamEventHandler ExamStarted;
public void myExam()
{
Console.WriteLine("Exam is Starting..");
Thread.Sleep(2000);
OnExamStarted();
}
//Subscriber or Receiver
class NotificationService
{
//Handler : That Match Delegate Signature
public void OnExamStarted(object source, EventArgs args)
{
Console.WriteLine("Your time starts now | start answering..");
20
Output
EXERCISE:9.
Here is a procedure to create a basic calculator. In this section I will build a basic calculator that can
perform the following operations:
21
Addition
Subtraction
Multiplication
Division
Clear
Steps:
Open Microsoft Visual Studio 2010 then click on "File" -> "New" -> "Website".
22
23
And click "Add". Now it will open the page as in the following:
24
5 Buttons to perform operation (addition (+), Subtraction (-) , Multiplication (*), Division (/)
,Clear (CLR) )
Default.aspx
Default.aspx.cs
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections.Generic;
public partial class _Default : System.Web.UI.Page
{
static float a, c,d;
static char b;
protected void Page_Load(object sender, EventArgs e)
{
25
}
protected void b1_Click1(object sender, EventArgs e)
{
if ((t.Text == "+") || (t.Text == "-") || (t.Text
{
t.Text = "";
t.Text = t.Text + b1.Text;
}
else
t.Text = t.Text + b1.Text;
}
protected void b3_Click(object sender, EventArgs e)
{
if ((t.Text == "+") || (t.Text == "-") || (t.Text
{
t.Text = "";
t.Text = t.Text + b3.Text;
}
else
t.Text = t.Text + b3.Text;
}
protected void b2_Click(object sender, EventArgs e)
{
if ((t.Text == "+") || (t.Text == "-") || (t.Text
{
t.Text = "";
t.Text = t.Text + b2.Text;
}
else
t.Text = t.Text + b2.Text;
}
protected void b4_Click(object sender, EventArgs e)
{
if ((t.Text == "+") || (t.Text == "-") || (t.Text
{
t.Text = "";
t.Text = t.Text + b4.Text;
}
else
t.Text = t.Text + b4.Text;
}
protected void b5_Click(object sender, EventArgs e)
{
if ((t.Text == "+") || (t.Text == "-") || (t.Text
{
t.Text = "";
t.Text = t.Text + b5.Text;
}
else
t.Text = t.Text + b5.Text;
}
protected void b6_Click(object sender, EventArgs e)
{
if ((t.Text == "+") || (t.Text == "-") || (t.Text
{
t.Text = "";
t.Text = t.Text + b6.Text;
}
else
26
27
b = '/';
t.Text += b;
}
protected void clr_Click(object sender, EventArgs e)
{
t.Text = "";
}
protected void add_Click1(object sender, EventArgs e)
{
a = Convert.ToInt32(t.Text);
t.Text = "";
b = '+';
t.Text += b;
}
protected void t_TextChanged(object sender, EventArgs e)
{
}
protected void eql_Click(object sender, EventArgs e)
{
c = Convert.ToInt32(t.Text);
t.Text = "";
if (b == '/')
{
d = a / c;
t.Text += d;
a = d;
}
else if (b == '+')
{
d = a + c;
t.Text += d;
a = d;
}
else if (b == '-')
{
d = a - c;
t.Text += d;
a = d;
}
else
{
d = a * c;
t.Text += d;
a = d;
}
}
-----------
output
28
29
30
EXERCISE:10.
System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;
namespace progressbar
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int i;
progressBar1.Minimum = 0;
progressBar1.Maximum = 200;
Output
31
10.b)DATETIMEPICKER CONTROL
1.go to windows application
2.Add DateTimePicker control(All windows form)
32
System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;
namespace date_time_picker
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
DateTime iDate;
iDate = dateTimePicker1.Value;
MessageBox.Show("Selected date is " + iDate);
}
/*dbl click form window Form1_Load. Appear*/
private void Form1_Load(object sender, EventArgs e)
{
dateTimePicker1.Format = DateTimePickerFormat.Short;
dateTimePicker1.Value = DateTime.Today;
}
}
}
output
33
10.c)SCROLL BAR
1.go to windows application
2.add text box
34
System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;
namespace scroll_bar
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
textBox1.Multiline = true;
textBox1.ScrollBars = ScrollBars.Both;
}
}
Output
35
36