0% found this document useful (0 votes)
38 views77 pages

C# .NET Framework Lab Manual 2021

Uploaded by

Hanock Jacob
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views77 pages

C# .NET Framework Lab Manual 2021

Uploaded by

Hanock Jacob
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

C# & .

NET FRAMEWORK LAB MANUAL


Department of Computer Science and
Engineering

C# & .NET FRAMEWORK LAB MANUAL

Lab Manual for the Academic Year 2020-2021


III [Link] IIsem

Rajeev Gandhi Memorial College Of


Engineering and
Technology(Autonomous)
Nandyal, Kurnool District – 518 501 (A. P.)

In-charge

G. RAJA SEKHAR REDDY

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 1


RAJEEV GANDHI MEMORIAL COLLEGE OF ENGINEERING & TECHNOLOGY
(AUTONOMOUS)
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

VISION OF THE DEPARTMENT

 To empower students with cutting edge technologies in computer science


and engineering

 To train the students as entrepreneurs in computer science and


engineering to address the needs of the society

 To develop smart applications to disseminate information to rural people

MISSION OF THE DEPARTMENT

 To become the best computer science and engineering department in the


region offering undergraduate, post graduate and research programs in
collaboration with industry

 To incubate, apply and spread innovative ideas by collaborating with


relevant industries and R & D labs through focused research groups.

 To provide exposure to the students in the latest tools and technologies to


develop smart applications for the society
C# & .NET FRAMEWORK LAB MANUAL
III B. Tech. II- Sem (CSE) Practical Credits
3 2
(A0594155) C# & .NET FRAMEWORK LAB
(COMMON TO CSE & IT)
OBJECTIVE:
 The student will gain knowledge in the concepts of the .NET
framework as a whole and the technologies that constitute the
Framework.
 The student will gain programming skills in C# both in basic and
advanced levels.
 By building sample applications, the student will get experience and
be ready for large-scale projects.

OUTCOMES:
 Write, compile and debug programs in C# language.
 To learn the basics of object oriented programming.
 To get knowledge of windows programming.
 To get knowledge on server side programming.
 To gain knowledge on web services and dynamic link libraries.
CO-PO MAPPING:
CO P P P P P P P P P P P P PS PS PS
/PO O O O O O O O O O O O O O1 O2 O3
1 2 3 4 5 6 7 8 9 10 11 12
CO1
1 1 1 1 2 1 1 1 2
CO2
2 2 1 1 2 1 1 2
CO3 2 2 2 2 2 1 2 2
CO4
2 2 1 1 3 1 1 2
CO5 2 2 2 2 2 1 2 1

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 2


C# & .NET FRAMEWORK LAB MANUAL
LAB-1
1. Write a program to C# to find the smallest single digit factor for a
given value.
2. Write a program in C# to print a number if it is prime; otherwise
display the largest factor of that number.
3. Write a program in C# to find the magnitude of a number.

LAB-2
1. Write a C# program for addition and multiplication of two matrices.
2. Write a C# program to display the digits of an integer in words.
3. Write a C# program to which reads a set of strings into the rows a two
dimensional array and then prints the string having more number of
vowels.

LAB-3
1. Write a C# programs to demonstrate the concepts of Structures and
Enumerations.
2. Write a C# programs to demonstrate the concepts of Constructors and
Inheritance.
3. Write a C# programs to demonstrate the concepts of Polymorphism.

LAB-4
1. Write a C# programs to demonstrate the concepts of Partial classes
and Extension methods.
2. Write a C# programs to demonstrate the concepts of Delegates.

LAB-5
1. Write a C# programs to demonstrate the concepts of Label, Text Box
and Button controls.
2. Write a C# programs to demonstrate the concepts of Combo Box and
List Box controls.

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 3


C# & .NET FRAMEWORK LAB MANUAL
LAB-6
1. Create a Windows application in C# for registration form and fill the
details and when you click the submit button it display the details in
the message box.
2. Create a Windows application in C# having two text boxes and three
buttons named as factorial, prime, factorial series. When you click any
button the resultant value will be displayed on the second textbox.

LAB-7
1. Create a [Link] application in C# to verify if the connection is
established with OLEDB and MS-ACCESS.
2. Create a [Link] applications in C# to demonstrate the Data Reader,
Data Set, Data Adapter and Data View Objects.

LAB-8
1. Develop the Static Web pages using HTML and some validations along
with Java Script.
2. Design an [Link] Webpage to demonstrate the Label, Button and
Textbox controls.

LAB-9
1. Design an [Link] Webpage to work with Cross page and Post back
Submissions.
2. Design an [Link] Webpage to work with Dropdown list and ListBox
controls.

LAB-10
1. Develop a Registration Form with all Validation Controls.
2. Create a Web Service for all Arithmetic operations.

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 4


C# & .NET FRAMEWORK LAB MANUAL
LAB-11
1. Write a C# program to implement Assemblies.
2. Write a C# program to implement Multithreading and Thread
Synchronization.

REFERENCES:
1. Programming in C#, E. Balagurusamy, Tata McGraw-Hill, 2004.
2. Programming C#, J. Liberty, 2nd Edition., O’Reilly, 2002.
3. C# and the .NET Platform, Andrew Trolesen, 2nd Edition, Dreamtech
Press
4. Sams Teach Yourself the C# Language in 21 Days’, Bradley L Jones,
1st edition, 2001.

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 5


C# & .NET FRAMEWORK LAB MANUAL
LAB1:
1. Write a program to C# to find the smallest single digit factor for a
given value.
using System;
namespace Factor
{
class Program
{
public static void main( )
{
int i=2,n;
[Link](“enter n value”);
n=[Link]([Link]);
while(i<=n)
{
if(n<10&&i<=n)
{
[Link](n+”doesn’t have single
digit factor other than one”);
break;
}
if(n%i==0)
{
[Link](i+”is smallest factor”);
break;
}
i++;
}
[Link]();
}
}
}

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 6


C# & .NET FRAMEWORK LAB MANUAL
2. Write a program in C# to print a number if it is prime; otherwise
display the largest factor of that number.
using System;
namespace prime
{
class Pro
{
public static void main()
{
int i,c,m=1;
[Link](“Enter a value”);
int n=[Link]([Link]());
c=0;i=1;
while(i<=n)
{
if(n%i==0)
{
if(i!=n)
m=I;
c++;
}
i++;
}
if(c==2)
[Link](“num is prime”);
else
[Link](m+ “is largest factor for “+n);
[Link]();
}
}
}

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 7


C# & .NET FRAMEWORK LAB MANUAL
3. Write a program in C# to find the magnitude of a number.
using System;
namespace c
{
class pro
{
public static void main(String[] args)
{
int n,i=0;
[Link](“enter n value”);
int n=[Link]([Link]());
while(n>0)
{
i++;
n=n/10;
}
[Link](“Magnitude of given num is:”+i);
}
}
}

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 8


C# & .NET FRAMEWORK LAB MANUAL
Lab-2:
1. Write a C# program for addition and multiplication of two matrices.
using System;
namespace matrix
{
class Pro1
{
public static void main(String[] args)
{
int i,j,m,n,p,q;
int [,]a=new int[30,30];
int [,]b=new int[30,30];
int[,]c=new int[30,30];
[Link](“enter rows and colums of first
matrix”);
m=Convert.Toint32([Link]());
n= Convert.Toint32([Link]());
[Link](“enter rows and colums of second
matrix”);
p=Convert.Toint32([Link]());
q= Convert.Toint32([Link]());
[Link](“Elemnts of first matrix”);
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
a[i,j]=[Link]([Link]());
}
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
b[i,j]=[Link]([Link]());
}
if((m==p) && (n==q))

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 9


C# & .NET FRAMEWORK LAB MANUAL
{
[Link](“addition is possible”);
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
c[I,j]=a[I,j]+b[I,j];
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
[Link](c[I,j]+”/t”);
[Link](“/n”);
}
}
else
[Link](“addition is not possible”);
if(n!=p)
[Link](“Mul is not possible”);
else
{
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
c[I,j]=0;
for(k=0;k<m&&k<q;k++)
c[I,j]=c[I,j]+a[I,k]*b[k,j];
}
}
[Link](“The matrix is”);
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 10


C# & .NET FRAMEWORK LAB MANUAL
[Link](“\t”+c[I,j]);
[Link](“\n”);
}
}
}
}
}

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 11


C# & .NET FRAMEWORK LAB MANUAL
2. Write a C# program to display the digits of an integer in words.
using System;
namespace Application
{
class Program
{
public static void main(String[] args)
{
int num,nextdigit,numdigits;
int[] n=new int[20];
string[] digits={“zero”,”one”,”two”,”three”,”four”,”five”,”six”,
”seven”,eight”,”nine”,};
[Link](“enter the number”);
num=Convert.ToInt32([Link]());
[Link](“number”+num);
[Link](“number in words”);
nextdigit=0;
numdigits=0;
do
{
nextdigits=num%10;
n[numdigits]=nextdigit;
numdigits++;
num=num/10;
}while(num>0);
numdigits--;
for( ;numdigits>=0;numdigits--)
[Link](digits[n[numdigits]]+” “);
[Link]();
}
}
}

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 12


C# & .NET FRAMEWORK LAB MANUAL
3. Write a C# program to which reads a set of strings into the rows a
two dimensional array and then prints the string having more number
of vowels.
using System;
using [Link];
using [Link];
using [Link];
namespace Program
{
class B
{
public static void main(String[] args)
{
string[,]a =new String[10,10];
char[] x=new Char[10];
int[] t=new int[10];
string[] g=new String[10];
string b;
[Link](“enter rows”);
int m=int .Parse([Link]());
[Link](“enter coloumns”);
int n=[Link](“[Link]());
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
a[I,j]=[Link]();
}
int k=0,c=0,s=0;
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
b=a[I,j];

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 13


C# & .NET FRAMEWORK LAB MANUAL
c=0;
for(k=0;k<[Link];k++)
{
if(b[k]==’a’)
c++;
else if(b[k]==’e’)
c++;
else if(b[k]==’I’)
c++;
else if(b[k]==’o’)
c++;
else if(b[k]==’u’)
c++;
}
g[s]=b;
t[s]=c;
s++;
}
}
int temp;
string tem;
for(int j=0;j<s;j++)
{
for(int i=0;i<s;i++)
{
if(t[i]>=t[j])
{
temp=t[i];
t[i]=t[j];
t[j]=temp;
temp=g[i];
g[i]=g[j];
g[j]=temp;

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 14


C# & .NET FRAMEWORK LAB MANUAL
}
}
}
[Link](“strings having more numbers of
vowels are”);
for(int i=0;i<s;i++)
{
if(t[i]<=t[s-1])
[Link](g[i]);
}
[Link](“word has “+t[s-1]+”vowels);
[Link]();
}
}
}

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 15


C# & .NET FRAMEWORK LAB MANUAL
Lab-3
1. Write a C# programs to demonstrate the concepts of Structures.
using System;
struct Books
{
public string title, author, subject;
public int book_id;
};
public class testStructure
{
public static void Main(string[] args)
{
Books Book1;
Books Book2;
[Link] = "C Programming";
[Link] = "Nuha Ali";
[Link] = "C Programming Tutorial";
Book1.book_id = 6495407;
[Link] = "Telecom Billing";
[Link] = "Zara Ali";
[Link] ="Telecom Billing Tutorial";
Book2.book_id = 6495700;
[Link]( "Book 1 title : {0}", [Link]);
[Link]("Book 1 author : {0}", [Link]);
[Link]("Book 1 subject : {0}", [Link]);
[Link]("Book 1 book_id :{0}", Book1.book_id);
[Link]("Book 2 title : {0}", [Link]);
[Link]("Book 2 author : {0}", [Link]);
[Link]("Book 2 subject : {0}", [Link]);
[Link]("Book 2 book_id : {0}", Book2.book_id);
[Link]();
}
}

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 16


C# & .NET FRAMEWORK LAB MANUAL
Write a C# programs to demonstrate the concepts of Enumerations.
using system
class Enumtype
{
enum Direction
{
North,
East==10,
West,
South
}
public static void Main()
{
Direction d1=0,
Direction d2= [Link];
Direction d3= [Link];
Direction d4= (Direction)12;
[Link](“d1=”+d1);
[Link](“d2=”+(int)d2);
[Link](“d3=”+d3);
[Link](“d4=”+d4);
}
}

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 17


C# & .NET FRAMEWORK LAB MANUAL
2. Write a C# programs to demonstrate the concepts of Default
Constructors
using System;
namespace ConsoleApplication3
{
class Sample
{
public string param1, param2;
public Sample() // Default Constructor
{
param1 = "Welcome";
param2 = "Aspdotnet-Suresh";
}
}
class Program
{
static void Main(string[] args)
{
Sample obj=new Sample();
[Link](obj.param1);
[Link](obj.param2);
[Link]();
}
}
}

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 18


C# & .NET FRAMEWORK LAB MANUAL
Write a C# programs to demonstrate the concepts of Parameterized
Constructors
using System;
namespace ConsoleApplication3
{
class Sample
{
public string param1, param2;
public Sample(string x, string y
{
param1 = x;
param2 = y;
}
}
class Program
{
static void Main(string[] args)
{
Sample obj=new Sample("Welcome","[Link]");
Sample obj1=new Sample("Welcome1","[Link]");
[Link](obj.param1 +" to "+ obj.param2);
[Link](obj1.param1 +" to "+ obj1.param2);
[Link]();
}
}
}

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 19


C# & .NET FRAMEWORK LAB MANUAL
Write a C# programs to demonstrate the concepts of copy Constructors
using System;
namespace ConsoleApplication3
{
class Sample
{
public string param1, param2;
public Sample(string x, string y)
{
param1 = x;
param2 = y;
}
public Sample(Sample obj) // Copy Constructor
{
param1 = obj.param1;
param2 = obj.param2;
}
}
class Program
{
static void Main(string[] args)
{
Sample obj = new Sample("Welcome", "[Link]");
Sample obj1=new Sample(obj);
[Link](obj1.param1 +" to " + obj1.param2);
[Link]();
}
}
}

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 20


C# & .NET FRAMEWORK LAB MANUAL
Write a C# programs to demonstrate the concepts of static
Constructors
using System;
namespace ConsoleApplication3
{
class Sample
{
public string param1, param2;
static Sample()
{
[Link]("Static Constructor");
}
public Sample()
{
param1 = "Sample";
param2 = "Instance Constructor";
}
}
class Program
{
static void Main(string[] args)
{
Sample obj=new Sample();
[Link](obj.param1 + " " + obj.param2);
Sample obj1 = new Sample();
[Link](obj1.param1 +" " + obj1.param2);
[Link]();
}
}
}

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 21


C# & .NET FRAMEWORK LAB MANUAL
Write a C# programs to demonstrate the concepts of private
Constructors
using System;
namespace ConsoleApplication3
{
public class Sample
{
public string param1, param2;
public Sample(string a,string b)
{
param1 = a;
param2 = b;
}
private Sample() // Private Constructor Declaration
{
[Link]("Private Constructor with no pramete");
}
}
class Program
{
static void Main(string[] args)
{
Sample obj = new Sample("Welcome","to [Link]");
[Link](obj.param1 +" " + obj.param2);
[Link]();
}
}
}

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 22


C# & .NET FRAMEWORK LAB MANUAL
Write a C# programs to demonstrate the concepts of single Inheritance
using System;
namespace InheritanceApplication
{
class a
{
public void display()
{
[Link]("hahahaha");
}
}
class b : a //b is child of a
{
public void display1()
{
[Link]("hihihih");
}
}
class c
{
public static void Main()
{
b x=new b();//Normally object of child
[Link]();
x.display1();
}
}
}

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 23


C# & .NET FRAMEWORK LAB MANUAL
Write a C# programs to demonstrate the concepts of Hierarchical
Inheritance
using System;
using [Link];
using [Link];
using [Link];
namespace Inheritance
{
class Program
{
static void Main(string[] args)
{
Principal g = new Principal();
[Link]();
Teacher d = new Teacher();
[Link]();
[Link]();
Student s = new Student();
[Link]();
[Link]();
[Link]();
}
class Principal
{
public void Monitor()
{
[Link]("Monitor");
}
}
class Teacher : Principal
{
public void Teach()
{

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 24


C# & .NET FRAMEWORK LAB MANUAL
[Link]("Teach");
}
}
class Student : Principal
{
public void Learn()
{
[Link]("Learn");
}
}
}
}

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 25


C# & .NET FRAMEWORK LAB MANUAL
Write a C# programs to demonstrate the concepts of multilevel
Inheritance
using System;
using [Link];
using [Link];
using [Link];
namespace ConsoleApplication8
{
class a
{
public void display()
{
[Link]("hahahaha");
}
}
class b : a //b is child of a
{
public void display1()
{
[Link]("hihihih");
}
}
class d : b //d is child of b
{
public void display2()
{
[Link]("hohohohoh");
}
}
class c
{
public static void Main()
{

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 26


C# & .NET FRAMEWORK LAB MANUAL
d x = new d();//Normally object of child
[Link]();
x.display1();
x.display2();
}
}
}

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 27


C# & .NET FRAMEWORK LAB MANUAL
3. Write a C# programs to demonstrate the concepts of Polymorphism.
Write a C# programs to demonstrate the concepts of method
overloading.
using System;
namespace PolymorphismApplication
{
class Printdata
{
void print(int i)
{
[Link]("Printing int: {0}", i );
}
void print(double f)
{
[Link]("Printing float: {0}" , f);
}
void print(string s)
{
[Link]("Printing string: {0}", s);
}
static void Main(string[] args)
{
Printdata p = new Printdata();
[Link](5);
[Link](500.263);
[Link]("Hello C++");
[Link]();
}
}
}

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 28


C# & .NET FRAMEWORK LAB MANUAL
Write a C# programs to demonstrate the concepts of constructor overloading.
using System;
namespace ConsoleApplication3
{
class Sample
{
public string param1, param2;
public Sample() // Default Constructor
{
param1 = "Hi";
param2 = "I am Default Constructor";
}
public Sample(string x, string y)
{
param1 = x;
param2 = y;
}
}
class Program
{
static void Main(string[] args)
{
Sample obj = new Sample();
Sample obj1=new Sample("Welcome","[Link]");
[Link](obj.param1 + ", "+obj.param2);
[Link](obj1.param1 +" to " + obj1.param2);
[Link]();
}
}

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 29


C# & .NET FRAMEWORK LAB MANUAL
Write a C# programs to demonstrate the concepts of unary operator
overloading.
using System;
class bank
{
int x;
int y;
public bank(int a, int b)
{
x = a;
y = b;
}
public bank()
{
}
public void display()
{
[Link](" " + x);
[Link](" " + y);
[Link]();
}
public static bank operator -(bank b)
{
b.x = -b.x;
b.y = -b.y;
return b;
}
}
class program
{
public static void Main()
{
bank ba1 = new bank(10,-20);

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 30


C# & .NET FRAMEWORK LAB MANUAL
[Link]();
bank ba2 = new bank();
[Link]();
ba2 = -ba1;
[Link]();
[Link]();
}
}

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 31


C# & .NET FRAMEWORK LAB MANUAL
Write a C# programs to demonstrate the concepts of binary operator
overloading.
using System;
namespace binary_overload
{
class complexNumber
{
int x;
double y;
public complexNumber(int real, double imagnary)
{
x = real;
y = imagnary;
}
public complexNumber()
{
}
public static complexNumber operator +(complexNumber c1,
complexNumber c2)
{
complexNumber c = new complexNumber();
c.x=c1.x+c2.x;
c.y=c1.x-c2.y;
return c;
}
public void show()
{
[Link](x);
[Link]("+j"+y);
[Link]();
}
}
class Program

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 32


C# & .NET FRAMEWORK LAB MANUAL
{
static void Main(string[] args)
{
complexNumber p, q, r;
p = new complexNumber(10, 2.0);
q = new complexNumber(20, 15.5);
r = p + q;
[Link]("p=");
[Link]();
[Link]("q=");
[Link]();
[Link]("r=");
[Link]();
[Link]();
}
}

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 33


C# & .NET FRAMEWORK LAB MANUAL
Write a C# programs to demonstrate the concepts of comparison
operator overloading.
using System;
namespace comparison
{
class Vector
{
int x, y, z;
public Vector(int p, int q, int r)
{
x = p;
y = q;
z = r;
}
public static bool operator ==(Vector v1, Vector v2)
{
if (v1.x == v2.x && v1.y == v2.y && v1.z == v2.z)
return (true);
else
return (false);
}
public static bool operator !=(Vector v1, Vector v2)
{
return (!(v1 == v2));
}
}
class comparison
{
static void Main()
{
Vector v1 = new Vector(10, 20, 30);
Vector v2 = new Vector(40, 50, 60);
if (v1 == v2)

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 34


C# & .NET FRAMEWORK LAB MANUAL
[Link]("v1 and v2 both are Equal");
else
[Link]("v1 and v2 are not equal");
if (!(v1 == v2))
[Link]("true");
else
[Link]("false");
[Link]();
}
}
}

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 35


C# & .NET FRAMEWORK LAB MANUAL
LAB-4:
1. Write a C# programs to demonstrate the concepts of Partial classes
using System;
namespace App
{
public partial class partialclass
{
private int x;
private int y;
public partialclass(int x,int y)
{
this.x=x;
this.y=y;
}
}
public partial class partialclass
{
public void print()
{
[Link]("output values{0},{1}", x, y);
}
}
class test
{
public static void Main()
{
partialclass p=new partialclass(10,15);
[Link]();
[Link]();
}
}
}

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 36


C# & .NET FRAMEWORK LAB MANUAL
2. Write a C# programs to demonstrate the concepts of single cast
Delegates.
using System;
delegate int NumberChanger(int n);
namespace DelegateAppl
{
class TestDelegate
{
static int num = 10;
public static int AddNum(int p)
{
num += p;
return num;
}
public static int MultNum(int q)
{
num *= q;
return num;
}
public static int getNum()
{
return num;
}
static void Main(string[] args)
{
NumberChanger nc1 = new NumberChanger(AddNum);
NumberChanger nc2 = new NumberChanger(MultNum);
nc1(25);
[Link]("Value of Num: {0}", getNum());
nc2(5);
[Link]("Value of Num: {0}", getNum());
}
} }

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 37


C# & .NET FRAMEWORK LAB MANUAL
Write a C# programs to demonstrate the concepts of multi cast
Delegates.
using System;
delegate void mdelegate();
namespace DelegateAppl
{
class dm
{
static public void display()
{
[Link](“new delhi”);
}
static public void print()
{
[Link](“new york”);
}
}
class mtest
{
public static void Main()
{
mdelegate m1=new mdelegate([Link]);
mdelegate m2=new mdelegate([Link]);
mdelegate m3=m1+m2;
mdelegate m4=m2+m1;
mdelegate m5=m3-m2;
m3();
m4();
m5();
}
}
}

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 38


C# & .NET FRAMEWORK LAB MANUAL
LAB-5:
1. Write a C# programs to demonstrate the concepts of Label, Text Box
and Button controls.
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void textBox1_Validating(object sender, CalEventArgs e)
{
TextBox tb = sender as TextBox;
if ([Link] == "textBox1")
{
if ([Link]().Length == 0)
{
[Link]("cant leave empty");
[Link] = true;
return;
}
}
}

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 39


C# & .NET FRAMEWORK LAB MANUAL
private void textBox2_Validating(object sender, CancelEventArgs e)
{
TextBox tb = sender as TextBox;
if ([Link] == "textBox2")
{
if ([Link]().Length == 0)
{
[Link]("cant leave empty");
[Link] = true;
return;
}
}
}
private void button1_Click(object sender, EventArgs e)
{
string temp;
temp = [Link];
[Link] = [Link];
[Link] = temp;
[Link] = false;
}
private void textBox2_Leave(object sender, EventArgs e)
{
TextBox tb = sender as TextBox;
if ([Link] == "TextBox2")
{
if ([Link]().Length == 0)
{
[Link]("cant leave empty");
return;
}
}
}

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 40


C# & .NET FRAMEWORK LAB MANUAL
private void textBox1_Leave(object sender, EventArgs e)
{
TextBox tb = sender as TextBox;
if ([Link] == "TextBox1")
{
if ([Link]().Length == 0)
{
[Link]("cant leave empty");
return;
}
}
}

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 41


C# & .NET FRAMEWORK LAB MANUAL
2. Create a windows application in c# to demonstrate comboBox and
ListBox controls using button click event.
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace WindowsFormsApplication22
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
[Link]([Link]());
string str = " ";
foreach (object ob in [Link])
{
str += [Link]() + " ,";
}
str = [Link](0, [Link]);
[Link](str);
}
}
}

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 42


C# & .NET FRAMEWORK LAB MANUAL
Lab-6:
1. Create a Windows application in C# for registration form and fill the
details and when you click the submit button it display the details in
the message box.

Properties:
1. Textbox2->passwordchar=*,maxlength=10
2. Textbob3->passwordchar=*
3. Textbox5->multiline=true
using System;
using [Link];
namespace WindowsFormsApplication21
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void textBox1_Validating(object sender, CancelEventArgs e)
{
TextBox tb = sender as TextBox;
if ([Link] == "textBox1")
{
if ([Link]().Length == 0)
{
[Link]("cannot leave empty");
[Link] = true;
return;
}
}
}

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 43


C# & .NET FRAMEWORK LAB MANUAL
private void textBox2_Validating(object sender, CancelEventArgs e)
{
TextBox tb = sender as TextBox;
if ([Link] == "textBox2")
{
if ([Link]().Length == 0)
{
[Link]("cannot leave empty");
[Link] = true;
return;
}
}
}
private void textBox3_Validating(object sender, CancelEventArgs e)
{
TextBox tb = sender as TextBox;
if ([Link] == "textBox3")
{
if ([Link]() != [Link]())
{
[Link]("not matched");
[Link] = true;
return;
}
}
}
private void textBox4_KeyPress(object sender, KeyPressEventArgs e)
{
if ([Link]([Link]) == false)
{
[Link]("enter only numbers");
[Link] = true;
return;

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 44


C# & .NET FRAMEWORK LAB MANUAL
}
}
private void button1_Click(object sender, EventArgs e)
{
[Link]("name=" + [Link] + "\n password=" +
[Link] + "\n confirm password=" + [Link] +
"\n age=" + [Link] + "\n address=" +
[Link]);
}
}
}

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 45


C# & .NET FRAMEWORK LAB MANUAL
2. Create a Windows application in C# having two text boxes and three
buttons named as factorial, prime, factorial series. When you click any
button the resultant value will be displayed on the second textbox.
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace WindowsFormsApplication11
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int n, i = 1, fact = 1;
n=[Link]([Link]);
while (i <= n)
{
fact = fact * i;
i++;
}
[Link] = [Link]();
}
private void button2_Click(object sender, EventArgs e)
{
int i, j, c;
int n = [Link]([Link]);
[Link] = "";

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 46


C# & .NET FRAMEWORK LAB MANUAL
for (j = 2; j <= n; j++)
{
c = 0;i = 1;
while (i <= j)
{
if (j % i == 0)
{
c++;
}
i++;
}
if (c <= 2)
{
[Link] = [Link] + [Link]() + ",";
}
}
}
private void button3_Click(object sender, EventArgs e)
{
int prev=0, cur=1, next;
int n = [Link]([Link]);
[Link] = [Link]() + [Link]();
next = prev + cur;
while (next <=n)
{
[Link] = [Link] + [Link]();
prev = cur;
cur = next;
next = prev + cur;
}
}
}
}

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 47


C# & .NET FRAMEWORK LAB MANUAL
LAB-7:
1. Create a [Link] application in C# to verify if the connection is
established with OLEDB and MS-ACCESS.
using System;
using [Link];
using [Link];
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string connetionString = null; OdbcConnection cnn ;
connetionString = "Driver={Microsoft Access Driver
(*.mdb)};DBQ=[Link];";
cnn = new OdbcConnection(connetionString);
try
{
[Link]();
[Link] ("Connection Open ! ");
[Link]();
}
catch (Exception ex)
{
[Link]("Can not open connection ! ");
}
}
}
}

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 48


C# & .NET FRAMEWORK LAB MANUAL
2. Create a [Link] applications in C# to demonstrate the Data
Reader, Data Set, Data Adapter and Data View Objects.
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace [Link]
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
static OleDbConnection con = new
OleDbConnection("provider=msdaora.1;user
id=system;password=uday");
OleDbDataReader dr;
Label[] L;
int x = 50;
TextBox[] T;
private void Form1_Load(object sender, EventArgs e)
{
OleDbCommand c1 = new OleDbCommand("select * from tab", con);
[Link]();
OleDbDataReader d = [Link]();
while ([Link]() == true)
{

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 49


C# & .NET FRAMEWORK LAB MANUAL
[Link](d[0].ToString());
}
[Link]();
}
private void button1_Click(object sender, EventArgs e)
{
if ([Link] == -1)
{
[Link]("kindly select a table first");
}
else
{
[Link]();
OleDbCommand cmd = new OleDbCommand("select * from
[Link]()", con);
dr = [Link]();
[Link]("no of cols" + [Link]);
L = new Label[[Link]];
T = new TextBox[[Link]];
for (int i = 0; i < [Link]; i++)
{
L[i] = new Label();
L[i].Text = [Link](i);
L[i].Location=new Point(100,x);
[Link](L[i]);
T[i] = new TextBox();
T[i].Location = new Point(200, x);
[Link](T[i]);
x = x + 30;
}
}
}

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 50


C# & .NET FRAMEWORK LAB MANUAL
private void button2_Click(object sender, EventArgs e)
{
if ([Link]() == true)
{
for (int i = 0; i < [Link]; i++)
T[i].Text = dr[i].ToString();
}
else
[Link]("No more records");
}

private void button3_Click(object sender, EventArgs e)


{
for (int i = 0; i < [Link]; i++)
{
[Link](L[i]);
[Link](T[i]);
}
[Link]();
x = 50;
}
}
}

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 51


C# & .NET FRAMEWORK LAB MANUAL
OledbConnection ocon;
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace WindowsFormsApplication25
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
OleDbConnection ocon;
private void button1_Click(object sender, EventArgs e)
{
ocon=new OleDbConnection("Provider=MSDAORA.1;user
id=system; password=raja;");
[Link]();
[Link]([Link]());
[Link]();
[Link]([Link]());
}
}
}

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 52


C# & .NET FRAMEWORK LAB MANUAL
Create a [Link] application in C#, to create a table and insert values
into created table.
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace WindowsFormsApplication25
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
OleDbConnection ocon;
OleDbCommand cmd1,cmd2;
private void button1_Click(object sender, EventArgs e)
{
con =new OleDbConnection("Provider=MSDAORA.1;
user id=system;password=raja;");
[Link]();
cmd1=new OleDbCommand("create table
student1(sid number,sname
varchar(10))",ocon);
cmd2=new OleDbCommand("insert into student1
values('1','raja')",ocon);
[Link]();
[Link]("table created");

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 53


C# & .NET FRAMEWORK LAB MANUAL
[Link]();
[Link]("1 row inserted");
}
}
}

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 54


C# & .NET FRAMEWORK LAB MANUAL
Create an [Link] application in C#, to retrieve the values from the
table using DataReader object.
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace WindowsFormsApplication25
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
OleDbConnection ocon;
OleDbDataReader dr;
private void Form1_Load(object sender, EventArgs e)
{
ocon = new OleDbConnection("Provider=MSDAORA.1;
user id=system; password=raja");
[Link]();
OleDbCommand cmd2 = new OleDbCommand("select * from
student4", ocon);

dr = [Link]();
[Link] = [Link](0);
[Link] = [Link](1);
}

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 55


C# & .NET FRAMEWORK LAB MANUAL
private void button1_Click(object sender, EventArgs e)
{
if ([Link]())
{
[Link] = [Link](0).ToString();
[Link] = [Link](1).ToString();
}
else
{
[Link]("no more records");
}
}
private void button2_Click(object sender, EventArgs e)
{
[Link]();
[Link]([Link]());
}
}
}

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 56


C# & .NET FRAMEWORK LAB MANUAL
Create an [Link] application in C#, to demonstrate DataAdapter
object
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace WindowsFormsApplication25
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
OleDbConnection ocon;
OleDbDataReader dr;
DataSet ds = new DataSet();
OleDbDataAdapter da;
int i, c, n;
private void Form1_Load(object sender, EventArgs e)
{
ocon = new OleDbConnection("Provider=MSDAORA.1;
user id=system; password=raja");
OleDbCommand cmd = new OleDbCommand("select *
from student4", ocon);
OleDbDataAdapter da = new OleDbDataAdapter("select *
from student4", ocon);
[Link]();

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 57


C# & .NET FRAMEWORK LAB MANUAL
dr = [Link]();
[Link] = [Link](0);
[Link] = [Link](1);
[Link](ds, "student4");
while ([Link]() != false)
{
c++;
}
n = c-1;
}
private void button1_Click(object sender, EventArgs e)
{
i = 0;
[Link] = [Link]["student4"].Rows[i][0].ToString();
[Link] = [Link]["student4"].Rows[i][1].ToString();
}
private void button2_Click(object sender, EventArgs e)
{
if (i < n)
{
i++;
[Link] = [Link]["student4"].Rows[i][0].ToString();
[Link] = [Link]["student4"].Rows[i][1].ToString();
}
else
{
[Link]("no more records");
}
}
private void button3_Click(object sender, EventArgs e)
{
if (i > 0)
{

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 58


C# & .NET FRAMEWORK LAB MANUAL
i--;
[Link] = [Link]["student4"].Rows[i][0].ToString();
[Link] = [Link]["student4"].Rows[i][1].ToString();
}
else
{
[Link]("no more records");
}
}
private void button4_Click(object sender, EventArgs e)
{
i = n;
[Link] = [Link]["student4"].Rows[i][0].ToString();
[Link] = [Link]["student4"].Rows[i][1].ToString();
}
}
}

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 59


C# & .NET FRAMEWORK LAB MANUAL
Create an [Link] application in C#, to demonstrate dataGridView
Control.
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace WindowsFormsApplication27
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
DataSet dset=new DataSet();
OleDbConnection ocon;
private void Form1_Load(object sender, EventArgs e)
{
ocon = new OleDbConnection("Provider=MSDAORA.1;user
id=system; password=raja");
OleDbDataAdapter ad = new OleDbDataAdapter(" select *
from student4", ocon);
[Link](dset,"student4");
[Link] = [Link]["student4"];
}
}
}

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 60


C# & .NET FRAMEWORK LAB MANUAL
LAB-8
1. Develop the Static Webpages using HTML and some validations along
with Java Script.

<html>
<head>
<script language=”javascript”>
function f1( )
{
D=new Date( );
h=[Link]( );
m=[Link] ( );
s=[Link]( );
[Link]=h+”:”+m+”:”+s;
[Link](“F1( )”,1000)
}
</script>
</head>
<body onload=”F1( )”>
<form name=”f”>
Time:<input type=”text” name=”t1”>
</form>
</body>
</html>

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 61


C# & .NET FRAMEWORK LAB MANUAL
LAB-9
1. Design an [Link] Webpage to work with Cross page and Post back
Submissions.
Creating a website to work with crosspage submission.
 Select [Link] empty website.
 Add web form and name it as [Link]
 Goto design view of [Link]

Uname:

Pwd :

Submit

 Place two labels, two textboxes and one submit button


 Label1 properties:
o id=l1
o Text=username
 Label2 properties:
 id=l2
 Text=password
 textBox1 properties:
id=t1
 textBox2 properties:
 id=t2
 textmode=password
 button1 properties:
 id=b1
 text=submit
 postbackurl=[Link]
 add webform(place one more web form into [Link] website) and
name it as [Link]

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 62


C# & .NET FRAMEWORK LAB MANUAL
 goto design view of [Link]
 place one label
 lebel1 properties
 id=lb
 code for page load event
{
String uname=[Link][“t1”];
String pwd=[Link][“t2”];
[Link]=”wel come to”+uname;
}
 to set login page as starting page
 goto solution explorer=>right click on [Link]=>set as start
page
 ctrl+f5

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 63


C# & .NET FRAMEWORK LAB MANUAL
Creating a website to work with postback submission
 Select [Link] empty website.
 Add web form and name it as [Link]
 Go to design view of [Link]

ACCNO:
Display

NAME :

 textBox2 properties:
 visible=false
 textBox3 properties:
 visible=false
 button1_click event logic
{
String[,]={{“60”,”uday”,”5000”},{“50”,”raja1”,”10000”}};
bool b=false;
if(s[I,0]==[Link])
{
[Link]=s[i,1];
[Link]=s[I,2];
[Link]=true;
[Link]=true;
b=true;
break;
}
if(b==false)
[Link](“accno not existing”);
}
 ctrl+f5

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 64


C# & .NET FRAMEWORK LAB MANUAL
2. Design an [Link] Webpage to work with Dropdown list and ListBox
controls.
Procedure:
1. Select [Link] empty website .
2. Add web form
3. Place one dropdownlist, two listboxes and four button on [Link]
design view.
Properties:
Dropdownlist1 properties:
 autopostback=true
 items= Microsoft, Microsoft1, Microsoft1
ListBox1 properties:
 selectMode=multiple
ListBox2 properties:
 selectMode=multiple
Button1 properties:
 Text =one(>)
Button2 properties:
 Text=multiple(>>)
Button3 properties:
 Text=removeone
Button4 properties:
 Text=removeall
using System;
using [Link];
using [Link];
using [Link];
namespace WebApplication2
{
public partial class WebForm1 : [Link]
{
protected void DropDownList1_SelectedIndexChanged(object sender,
EventArgs e)

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 65


C# & .NET FRAMEWORK LAB MANUAL
{ [Link]();
switch ([Link])
{
case "microsoft": [Link]("10");
[Link]("20");
break;
case " microsoft1": [Link]("100");
[Link]("200");
break;
case " microsoft2":[Link]("1000");
[Link]("2000");
break;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
[Link]([Link]);
}
protected void Button2_Click(object sender, EventArgs e)
{
for (byte i = 0; i < [Link]; i++)
[Link]([Link][i]);
}
protected void Button3_Click(object sender, EventArgs e)
{
[Link]([Link]);
}
protected void Button4_Click(object sender, EventArgs e)
{
[Link]();
}
}
}

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 66


C# & .NET FRAMEWORK LAB MANUAL
LAB-10
1. Develop a Registration Form with all Validation Controls.
Procedure:
1. Select [Link] empty website and name it as registration
2. Add webform([Link])
3. Place 5 lables,5 textboxes and 1 button
4. Place one RequiredFieldValidator,
one RangeValidator,
one CompareValidator,
one RegularExpressionValidator and
one ValidationSummary control on [Link] design view.
Properties:
textBox2:
 text=password
textBox3:
 text=password
RequiredFieldValidator1:
 ControlToValidate=textBox1
 ErrorMessage=Enter something
RangeValidator1:
 ControlToValidate=textBox4
 ErrorMessage=should be greater than 18
 Type=integer
CompareValidator1:
 ControlToCompare=textBox2
 ControlToValidate=textBox3
 ErrorMessage=doesnot match password
RegularExpressionValidator1:
 ControlToValidate=textBox5
 ErrorMessag=invalid email id
 validationExpression=select internet email address
ValidationSummary:
 HeaderText=you have received the following errors.

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 67


C# & .NET FRAMEWORK LAB MANUAL
2. Create a Web Service for all Arithmetic operations.
Procedure:
1. Go to visual studio File==>new==>website
2. In solution explorer Right click on project path and select webservice
and click on add.
3. Define web methods
[WebMethod]
public int add(int a, int b)
{ return a+b;
}
[WebMethod]
public int sub(int a, int b)
{
return a-b;
}
[WebMethod]
public int mul(int a, int b)
{
return a*b;
}
[WebMethod]
public int div(int a, int b)
{
return a/b;
}
[WebMethod]
public int moddiv(int a, int b)
{
return a%b;
}
 After writing the logic then go to debug select start without debugging
option
 The output window will be displayed in WSDL XML document

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 68


C# & .NET FRAMEWORK LAB MANUAL
LAB-11
1. Write a C# program to implement Private Assemblies.
Procedure:
 Open a new class library template(name as raja)
using System;
namespace raja
{
public class pa1
{
public string m1()
{
return "pa1 test";
}
}
namespace sekhar
{
public class pa2
{
public string m2()
{
return "pa2 test";
}
}
}
}
 Now build the project, it will generate .dll file in their project folder.
CONSUMING THE PRIVATE ASSEMBLY:
 Open winform app project(name as privateassembly)
 Place abutton
 To Add assembly to private assembly
Right click on Project path ==>add new item==>add
reference==>browse==>select [Link] file
 Then write the code under button click event

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 69


C# & .NET FRAMEWORK LAB MANUAL
using raja;
using [Link];
namespace WindowsFormsApplication32
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
pa1 p1 = new pa1();
[Link](p1.m1());
pa2 p2 = new pa2();
[Link](p2.m2());
}
}
}

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 70


C# & .NET FRAMEWORK LAB MANUAL
Write a C# program to implement shared Assemblies.
Procedure:
 Open class library template(name as uday)
using System;
namespace uday
{
public class r
{
public string a()
{
return "this is uday’s assembly";
}
}
}
 To create a strong name go to visual studio command prompt and set
the path upto debug folder(uday project path).
sn –k [Link]
 To link [Link] to uday
Right click on Project path ==> properties==> signing==>click
checkbox==>select browse from combobox==>choose [Link].
 Now build the project
build==>build uday
 Register [Link] with GAC(global assembly cache)(the location of GAC
folder is c:\windows\[Link]\assembly\GAC_MSIL)
gacutil –i [Link]
CONSUMING SHARED ASSEMBLY:
 Open winform project
 Place a button
 Right click on Project path ==>add
reference==>browse==>[Link]
using uday;
namespace WindowsFormsApplication33
{

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 71


C# & .NET FRAMEWORK LAB MANUAL
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
r b = new r();
[Link](b.a());
}
}
}

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 72


C# & .NET FRAMEWORK LAB MANUAL
2. Write a C# program to implement Multi Threading using System;
using [Link];
namespace ConsoleApplication11
{
class Program
{
public static void m1()
{
for (int i = 0; i <= 10; i++)
{
[Link](i + "");
[Link](500);
}
}
public static void m2()
{
for (int k = 11; k <= 20; k++)
{
[Link](k + ""); [Link](500);
}
}
}
class test
{
static void Main(string[] args)
{
ThreadStart ts1 = new ThreadStart(Program.m1);
ThreadStart ts2 = new ThreadStart(Program.m2);
Thread t1 = new Thread(ts1); Thread t2 = new Thread(ts2);
[Link](); [Link]();
}
}
}

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 73


C# & .NET FRAMEWORK LAB MANUAL
Write a C# program to implement Thread Synchronization
using System;
using [Link];
namespace ConsoleApplication13
{
class Program
{
Mutex m = new Mutex();
public void m1()
{
[Link]();
for (int i = 1; i <= 10; i++)
{
[Link](i + "");
[Link](500);
}
[Link]();
}
}
class test
{
static void Main(string[] args)
{
Program p = new Program();
ThreadStart ts1 = new ThreadStart(p.m1);
Thread t1= new Thread(ts1);
Thread t2 = new Thread(ts1);
[Link](); [Link]();
}
}
}

Prepared By: [Link] Sekhar Reddy, Dept Of CSE, RGMCET Page 74


RAJEEV GANDHI MEMORIAL COLLEGE OF ENGINEERING & TECHNOLOGY
(AUTONOMOUS)
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

Evaluation Procedure for Internal Laboratory Examinations:

1. Of the 25 marks for internal, 10 marks will be awarded for day-to-day work and 10 marks
to be awarded for the Record work and 5 marks to be awarded by conducting an internal
laboratory test.
2. Concerned Teachers have to do necessary corrections with explanations.
3. Concerned Lab teachers should enter marks in index page.
4. Internal exam will be conducted by two Staff members.

Dr.K. Subba Reddy


Professor & Head Dept. of CSE.
RAJEEV GANDHI MEMORIAL COLLEGE OF ENGINEERING & TECHNOLOGY
(AUTONOMOUS)
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

Evaluation Procedure for External Laboratory Examinations:

1. For Practical subjects there is a continuous evaluation during the semester for 25 Sessional
marks and 50 end examination marks.
2. The end examination shall be conducted by the teacher concerned (Internal Examiner) and
another External Examiner, recommended by Head of the Department with the approval of
principal.

Evaluation procedure for external lab examination:


1. Procedure for the program ---------- 20M
2. Execution of the program ---------- 15M
3. Viva voce ---------- 15M
----------------------------
Total 50M
-----------------------------

Dr.K. Subba Reddy


Professor & Head Dept. of CSE.

Common questions

Powered by AI

The ADO.NET framework facilitates database connectivity in C# by providing a comprehensive set of classes that enable various data operations such as retrieving, inserting, and updating data in databases. It primarily uses objects like Connection, Command, DataReader, DataAdapter, and DataSet. A Connection object, like OleDbConnection, is used to establish a link to the database, and a Command object executes SQL queries. DataReader is used for fast, forward-only retrieval of data, suitable for reading data directly from a data source . DataAdapter works alongside DataSet to manage data and synchronize changes back to the source without requiring a continuous connection, providing a robust way for data manipulation in disconnected environments . These objects enable developers to effectively manage and operate on data within C# applications, abstracting the complexity of the underlying relational operations.

To display the digits of an integer in words in C#, the program reads each digit individually, translates it into its corresponding text representation using an array of strings, and outputs the result. First, an array holds the words for digits zero through nine. The program extracts each digit by taking modulus 10 and stores them in reverse order . A loop then iterates through these 'next digit' indices, translating each to its word form using the predefined array and printing it as a coherent output in the correct order . This methodology efficiently processes each digit sequentially and outputs it as worded text, ensuring clarity and understanding.

Method overloading in C# enhances program efficiency and flexibility by allowing multiple methods with the same name but different parameter sets. This permits functions to be used more broadly without introducing entirely new method names, which conserves cognitive resources and simplifies interfaces. For instance, a class handling 'Printdata' could have overloaded methods to handle printing integers, floats, and strings, all within the same class context . This allows for a consistent interface for output operations while managing a variety of input types. Such overloading can reduce the need for type checks and conversions, leading to more streamlined and readable code. By processing distinct types of data inputs in this way, applications become more versatile and adaptable to different scenarios without the overhead of creating redundant functions.

Errors or exceptions in defining and using structures and enumerations in C# can lead to runtime errors or incorrect application behavior due to logical missteps. Structures must be properly initialized before use; otherwise, accessing uninitialized struct variables can lead to unpredictable results or exceptions . Similarly, enumerations must be correctly defined to avoid misinterpretation of integral values associated with enumeration names. For instance, if the Direction enum is incorrectly set or accessed, it can disrupt the intended program flow or lead to logic errors, especially if specific enum values are used as decision points in code . Both structures and enumerations require careful coding practices to ensure they function as intended, emphasizing the importance of knowledgable initialization and access practices in C# programming.

A C# program can determine whether an integer is prime by counting its divisors. The program iterates over numbers from 1 to the integer itself and counts how many numbers divide it evenly. If only two numbers divide the integer (1 and itself), it is prime. Otherwise, the integer is not prime . If the number is not prime, the largest factor can be identified by checking divisibility from 1 to the integer, keeping track of the highest divisor less than the number itself. This approach ensures that even when an integer isn't prime, its largest factor is found efficiently using iteration .

Polymorphism and method overloading are both strategies that provide flexibility in method invocation. Polymorphism allows methods to perform different functions based on the object instance, enabling runtime method binding or dynamic method invocation. For instance, if a 'Printdata' class has methods for printing integers, floats, and strings, the class can handle these different data types polymorphically by implementing separate overload functions for each data type . Method overloading, on the other hand, involves defining multiple methods with the same name but different parameters within the same class. It is an example of compile-time polymorphism, as the method to invoke is decided at the time of compilation . Thus, while both concepts enhance method functionality, polymorphism focuses on method behavior across different classes and objects, whereas method overloading focuses on providing multiple ways to call the same class method with different types/signature of parameters.

Default and parameterized constructors in C# play crucial roles in object creation and initialization. A default constructor initializes objects with default values, facilitating easy object instantiation without requiring explicit arguments during creation . Its presence ensures seamless object lifecycle management, permitting unobstructed object creation in versatile coding scenarios. Conversely, parameterized constructors require specified arguments, allowing for detailed object initialization by setting properties directly with intended values at creation time . This approach ensures that objects are created in well-defined states, aligning initialization closely with intended usage. Both constructors collectively provide robust mechanisms for flexibly managing object states, enhancing code organization and application logic.

Inheritance in C#, through its different forms (single, hierarchical, multilevel), helps in code reusability and simplicity by allowing derived classes to inherit methods and properties from a base class. This reduces redundancy and enables code maintenance. Single inheritance allows a class to inherit from one base class, as seen in the example where class B inherits from class A and can use its methods . Hierarchical inheritance extends the concept further by enabling multiple classes to inherit from a single base class, allowing shared functionalities among disparate classes . Multilevel inheritance involves a scenario where a class inherits from a class which is already a derived class, making it possible to build upon the functionalities further down the hierarchy . These patterns ensure that common functionalities do not need to be rewritten, thus simplifying code management and reducing errors across related programming tasks.

Creating a table and inserting records using ADO.NET in C# involves first establishing a connection to the database using a connection object, such as OleDbConnection. Next, a command object is initialized with the appropriate SQL statement to create a table and another for inserting records, employing OleDbCommand for execution. The application uses commands like 'ExecuteNonQuery' to apply these operations on the database . These steps differ from other data manipulation operations such as data retrieval because creating and inserting modify the database structure and contents, whereas retrieval operations like querying use DataReader for reading and displaying existing data without altering the database . Each operation employs specific methods optimized for its goal, collectively contributing to a comprehensive data management capability within C# applications.

In implementing matrix operations such as addition and multiplication, conditional statements and loops play crucial roles. The program checks the condition for matrix addition by verifying if the matrices have the same dimensions (i.e., the number of rows and columns are equal) before proceeding . For each element in the matrices, it then employs nested loops to iterate over rows and columns, performing the respective addition or multiplication. In the case of multiplication, the condition also checks that the number of columns in the first matrix matches the number of rows in the second matrix, ensuring multiplication validity . These logic gates ensure operations are performed correctly and handle possible exceptions or logical errors effectively.

You might also like