Sie sind auf Seite 1von 46

CONTENTS

Sl. No.
1 2 3 # & ( ) + * 1, 11 12 13 1# 1& 1( 1) 1+ 1* 2, 21 22 23

Particulars
Lab Instructions Hardware and Software e!uire"ents Introduction to .Net $ra"ewor% P' T ' Progra" 1 Progra" 2 Progra" 3 Progra" # Progra" & Progra" ( Progra" ) Progra" + Progra" * Progra" 1, Progra" 11 Progra" 12 Progra" 13 Progra" 1# Progra" 1& Progra" 1( Progra" 1) Progra" 1+ P' T - . Sa"/le for" Pro/osed 0I0' 1uestions

Page No.
3 # & 1& 1( 1) 1* 2, 2& 2+ 3, 33 3& 3( 3+ #, ## #* &, &3 &( &) &+

Prescribed Programs PART - A 1. Program in C# to Check whether a number is Palindrome or not.


using System; class Program { static void Main(string[] args) { string str = string.Empty; Console. rite!ine("Enter a #um$er or String"); string s = Console.%ead!ine(); int i = s.!engt&; ''(e can get t&e !engt& o) string $y using !engt& Property )or (int * = i + ,; * -= .; *++) { str = str / s[*]; 0 i) (str == s) { Console. rite!ine(s / " is palindrome"); 0 else { Console. rite!ine(s / " is not a palindrome"); 0 Console.%ead(); 0 0 Run 1 Enter a #um$er or String ,12 ,12 is not a palindrome Run 2 Enter a #um$er or String ,1, ,1, is palindrome Run 3 Enter a #um$er or String madam madam is palindrome

2. Program in C# to demonstrate Command line arguments processing.


using System; class 3elloClass { pu$lic static void Main(string[] args) { Console. rite!ine("444command line args444"); )or (int 5 = .; 5 6 args.!engt&; 5//) Console. rite!ine("7rg8 {.0"9 args[5]); Console. rite!ine("3ello (orld"); Console.%ead!ine(); 0 0 %un , 444command line args444 7rg8 CS&arp 7rg8 programming 7rg8 la$ 3ello (orld %un 1 444command line args444 3ello (orld

3. Program in C# to ind the roots o !uadratic "#uation.


using System; class :uadratic { pu$lic static void Main() { dou$le 5,9 51; Console. rite!ine(";uadratic E:uation Solution (a51/$5/c=.)"); Console. rite!ine("Enter value )or a"); int a = Convert.<o=nt21(Console.%ead!ine()); Console. rite!ine("Enter value )or $"); int $ = Convert.<o=nt21(Console.%ead!ine()); Console. rite!ine("Enter value )or c"); int c = Convert.<o=nt21(Console.%ead!ine()); dou$le d = $ 4 $ + > 4 a 4 c; i) (d == .) { 5, = 51 = (+$) ' (1 4 a); Console. rite!ine("?ot& root &ave same value8 " / 5,); 0 else i) (d - .) { Console. rite!ine("?ot& root &ave di))erent value"); 5, = (+$ / Mat&.S:rt(d)) ' (1 4 a); 51 = (+$ + Mat&.S:rt(d)) ' (1 4 a); Console. rite!ine("%oot,8 " / 5,); Console. rite!ine("%oot18 " / 51); 0 else { Console. rite!ine("%oots are imaginary"); 0 Console.%ead!ine(); 0 0 %un , ;uadratic E:uation Solution (a51/$5/c=.) Enter value )or a , Enter value )or $ 1 Enter value )or c , ?ot& root &ave same value8 +, %un 1 ;uadratic E:uation Solution (a51/$5/c=.) Enter value )or a 1 Enter value )or $ 2

Enter value )or c > %oots are imaginary %un 2 ;uadratic E:uation Solution (a51/$5/c=.) Enter value )or a , Enter value )or $ @ Enter value )or c > ?ot& root &ave di))erent value %oot,8 +..>ABBC,,1DBD.C1D %oot18 +B.D2,,1BBC>,>@1C

$. Program in C# to demonstrate bo%ing and un&o%ing.


using System; class $o5 { pu$lic static void Main() { Console. rite("EnEnter t&e num$erEt"); int n=int.Parse(Console.%ead!ine()); o$*ect o$=n; ''n is $o5ed in o$; Console. rite!ine("n= "/n); Console. rite!ine("o$= "/o$); int s=(int)o$; ''un$o5ing Console. rite!ine("o$= "/s); Console.%ead!ine(); 0 0 %un , Enter t&e num$er n= ,12 o$= ,12 o$= ,12 ,12

'. Program in C# to implement (tack operations.


using System; class stacF { pu$lic int [] st; pu$lic int top; pu$lic stacF() { top=+,; 0 pu$lic void siGe(int a) { st=ne( int[a]; 0 pu$lic void pus&(int item) { i)(top==st.!engt&+,) { Console. rite!ine("EnEtEtEtStacF over)lo(HHH"); 0 else { top//; st[top]=item; 0 0 pu$lic void pop() { i)(top==+,) Console. rite!ine("EnEtEtEtStacF under)lo(HHH"); else { int temp; temp=st[top]; Console. rite!ine("EnEtEtEtPopped item is 8"/temp); top++; 0 0 pu$lic void display() { i)(top==+,) Console. rite!ine("EnEtEtEtStacF is emptyHHH"); else { int temp=top; (&ile(tempH=+,) { Console. rite("Et"/st[temp]); temp++; 0 0 0 pu$lic void count() {

int counter=.; int temp=top; (&ile(tempH=+,) { counter//; temp++; 0 Console. rite!ine("EnEtEtEt<otal no. o) items is stacF is8 "/counter); 0 0 class test { pu$lic static void Main() { stacF o$,=ne( stacF(); Console. rite!ine("EnEnter siGe o) t&e stacFEt"); int len=int.Parse(Console.%ead!ine()); o$,.siGe(len); int c&; do { Console. rite!ine("EnEn44444444444444444444444444"); Console. rite!ine("En,.Pus&"); Console. rite!ine("En1.Pop"); Console. rite!ine("En2.Iisplay"); Console. rite!ine("En>.Count"); Console. rite!ine("EnD.E5it"); Console. rite!ine("EnEn44444444444444444444444444"); Console. rite!ine("EnEnter your c&oiceEt"); c&=int.Parse(Console.%ead!ine()); s(itc&(c&) { case ,8 Console. rite!ine("EnEnter itemEt"); int item=int.Parse(Console.%ead!ine()); o$,.pus&(item); $reaF; case 18 o$,.pop(); $reaF; case 28 o$,.display(); $reaF; case >8 o$,.count(); $reaF; case D8 $reaF; de)ault8 Console. rite!ine("EnEtEtEt=nvalid c&oiceHHH"); $reaF; 0 0(&ile(c&H=D);

0 0

%un , Enter siGe o) t&e stacF > 44444444444444444444444444 ,.Pus& 1.Pop 2.Iisplay >.Count D.E5it 44444444444444444444444444 Enter your c&oice , Enter item ,1 44444444444444444444444444 ,.Pus& 1.Pop 2.Iisplay >.Count D.E5it 44444444444444444444444444 Enter your c&oice , Enter item ,2 44444444444444444444444444 ,.Pus& 1.Pop 2.Iisplay

>.Count D.E5it 44444444444444444444444444 Enter your c&oice 2 ,2 ,1 44444444444444444444444444 ,.Pus& 1.Pop 2.Iisplay >.Count D.E5it 44444444444444444444444444 Enter your c&oice > <otal no. o) items is stacF is8 1 44444444444444444444444444 ,.Pus& 1.Pop 2.Iisplay >.Count D.E5it 44444444444444444444444444 Enter your c&oice 1 Popped item is 8,2 44444444444444444444444444 ,.Pus&

1.Pop 2.Iisplay >.Count D.E5it 44444444444444444444444444 Enter your c&oice 2 ,1 44444444444444444444444444 ,.Pus& 1.Pop 2.Iisplay >.Count D.E5it 44444444444444444444444444 Enter your c&oice D

). Program to demonstrate *perator o+erloading.


using System; class over { pu$lic int a; pu$lic int $; pu$lic over() { 0 pu$lic void value() { Console. rite!ine("EnEnter a8Et"); a = int.Parse(Console.%ead!ine()); Console. rite!ine("EnEnter $8Et"); $ = int.Parse(Console.%ead!ine()); 0 pu$lic over(int 59 int y) { a = 5; $ = y; 0 pu$lic void display() { Console. rite!ine("Ena= " / a / "En$= " / $); 0 pu$lic static over operator +(over t) { t.a = +t.a; t.$ = +t.$; return (t); 0 pu$lic static over operator /(over o$,9 over o$1) { over o$2 = ne( over(); o$2.a = o$,.a / o$1.a; o$2.$ = o$,.$ / o$1.$; return (o$2); 0 pu$lic static $ool operator ==(over o$,9 over o$1) { i) ((o$,.a == o$1.a) JJ (o$,.$ == o$1.$)) return (true); else return ()alse); 0 pu$lic static $ool operator H=(over o$,9 over o$1) { i) (H(o$, == o$1)) return (true); else return ()alse); 0 pu$lic static $ool operator -(over o$,9 over o$1)

0 class test { pu$lic static void Main() { over o$, = ne( over(); over o$1 = ne( over(); over o$2 = ne( over(); Console. rite!ine("Enter )or o$,++++++++++++"); o$,.value(); Console. rite!ine("Enter )or o$1++++++++++++"); o$1.value(); Console. rite!ine("Eno$,8++++++++-"); o$,.display(); Console. rite!ine("Eno$18++++++++-"); o$1.display(); i) (o$, == o$1) Console. rite!ine("o$, J o$1 are e:ual"); else i) (o$, - o$1) Console. rite!ine("o$, is greater t&an o$1"); else i) (o$, 6 o$1) Console. rite!ine("o$1 is greater t&an o$,"); else Console. rite!ine("o$, J o$1 are not e:ual"); o$, = +o$,; Console. rite!ine("Ena)ter negating o$,8++++++++-"); o$,.display(); o$1.display(); o$2 = o$, / o$1; Console. rite!ine("Eno$2=o$,/o$18++++++++-");

0 pu$lic static $ool operator 6=(over o$,9 over o$1) { i) (H(o$,.a - o$1.a)) return (true); else return ()alse); 0 pu$lic static $ool operator 6(over o$,9 over o$1) { i) (o$,.a 6 o$1.a) return (true); else return ()alse); 0 pu$lic static $ool operator -=(over o$,9 over o$1) { i) (H(o$,.a 6 o$1.a)) return (true); else return ()alse); 0

i) (o$,.a - o$1.a) return (true); else return ()alse);

o$2.display(); Console.%ead!ine(); 0 0

Run 1 Enter )or o$,++++++++++++ Enter a8 1 Enter $8 > Enter )or o$1++++++++++++ Enter a8 D Enter $8 2 o$,8++++++++a= 1 $= > o$18++++++++a= D $= 2 o$1 is greater t&an o$, a)ter negating o$,8++++++++a= +1 $= +> a= D $= 2 o$2=o$,/o$18++++++++a= 2 $= +,

,. Program in C# to ind the second largest element in a single dimensional arra-.


using System; class #um$erSorting { pu$lic static void Main() { int[] num$er; num$er = ne( int[,.]; Console. rite!ine("Enter t&e num$er o) elements"); int n = int.Parse(Console.%ead!ine()); Console. rite!ine("Enter t&e elements"); )or (int i = .; i 6 n; i//) { num$er[i] = int.Parse(Console.%ead!ine()); 0 '' Sorting $egins )or (int i = .; i 6 n; i//) { )or (int * = i / ,; * 6 n; *//) { i) (num$er[i] - num$er[*]) { int temp = num$er[i]; num$er[i] = num$er[*]; num$er[*] = temp; 0 0 0 Console. rite!ine("<&e sorted elements are"); )or (int i = .; i 6 n; i//) { Console. rite("En" / num$er[i]); 0 Console. rite!ine(" En <&e second largest element is 8 "); Console. rite(num$er[,]); Console.%ead!ine(); 0 0 %un , Enter t&e num$er o) elements > Enter t&e elements 12 ,1 +2> @B <&e sorted elements are +2> ,1 12

@B <&e second largest element is 8 ,1

Alternate program
using System; class seclargest { pu$lic static void Main() { int[] arr = ne( int[1.]; int temp9 i9 p9 s; p = .; s = .; Console. rite!ine("Second largest num$er"); Console. rite!ine("Enter t&e array siGe8 "); int n = int.Parse(Console.%ead!ine()); Console. rite!ine("Enter " / n / " num$ers"); )or (i = .; i 6 n; i//) { arr[i] = int.Parse(Console.%ead!ine()); 0 )or (i = .; i 6 n; i//) { temp = arr[i]; i) (temp - p) { s = p; p = temp; 0 i) (temp - s JJ temp 6 p) { s = temp; 0 0 Console. rite!ine("!argest num$er 8 " / p); Console. rite!ine("1nd largest num$er 8 " / s); Console.%ead!ine(); 0 0

%un , Second largest num$er Enter t&e array siGe8 D Enter D num$ers 1 12 , DA CB !argest num$er 8 CB 1nd largest num$er 8 DA

.. Program to multipl- 2 matrices using rectangular arra-s.


using System; class matKmul { pu$lic static void Main() { int[9] a; int[9] $; int[9] c; int i9 *9 F9 temp = .; Console. rite!ine("Matri5 Multiplication (Matri5,4Matri51)"); Console. rite!ine("Enter no. o) ro(s )or matri5,"); int ro(, = int.Parse(Console.%ead!ine()); Console. rite!ine("Enter no. o) columns )or matri5,"); int col, = int.Parse(Console.%ead!ine()); a = ne( int[ro(,9 col,]; Console. rite!ine("Enter " / ro(, 4 col, / " elements )or Matri5,"); )or (i = .; i 6 ro(,; i//) { )or (* = .; * 6 col,; *//) { a[i9 *] = int.Parse(Console.%ead!ine()); 0 0 Console. rite!ine(); Console. rite!ine("Enter no. o) ro( )or matri51"); int ro(1 = int.Parse(Console.%ead!ine()); Console. rite!ine("Enter no. o) columns )or matri51"); int col1 = int.Parse(Console.%ead!ine()); $ = ne( int[ro(19 col1]; c = ne( int[ro(,9 col1]; Console. rite!ine("Enter " / ro(1 4 col1 / " elements )or Matri51"); )or (i = .; i 6 ro(1; i//) { )or (* = .; * 6 col1; *//) { $[i9 *] = int.Parse(Console.%ead!ine()); 0 0 Console. rite!ine(); Console. rite!ine("Elements o) Matri5,++++++-"); )or (i = .; i 6 ro(,; i//) { )or (* = .; * 6 col,; *//) { Console. rite(" " / a[i9 *]); 0 Console. rite!ine(); 0 Console. rite!ine("Elements o) Matri51++++++-"); )or (i = .; i 6 ro(1; i//) {

0 0 %un ,

0 i) (col, H= ro(1) { Console. rite!ine("Matri5 multiplication is not possi$le"); temp = ,; 0 else { )or (i = .; i 6 ro(,; i//) { )or (* = .; * 6 col1; *//) { c[i9 *] = .; )or (F = .; F 6 col,; F//) { c[i9 *] = c[i9 *] / a[i9 F] 4 $[F9 *]; 0 0 0 0 i) (temp == .) { Console. rite!ine(); Console. rite!ine("Multiplication o) Matri, and Matri51++++++-"); )or (i = .; i 6 ro(,; i//) { )or (* = .; * 6 col1; *//) { Console. rite(" " / c[i9 *]); 0 Console. rite!ine(); 0 0 Console.%ead!ine();

)or (* = .; * 6 col1; *//) { Console. rite(" " / $[i9 *]); 0 Console. rite!ine();

Matri5 Multiplication (Matri5,4Matri51) Enter no. o) ro(s )or matri5, 1 Enter no. o) columns )or matri5, 2 Enter A elements )or Matri5, , 1 2 > D A

Enter no. o) ro( )or matri51 2 Enter no. o) columns )or matri51 1 Enter A elements )or Matri51 A D > 2 1 , Elements o) Matri5,++++++, 1 2 > D A Elements o) Matri51++++++A D > 2 1 , Multiplication o) Matri, and Matri51++++++1. ,> DA >, %un 1 Matri5 Multiplication (Matri5,4Matri51) Enter no. o) ro(s )or matri5, 1 Enter no. o) columns )or matri5, 2 Enter A elements )or Matri5, , 1 2 > D A Enter no. o) ro( )or matri51 1 Enter no. o) columns )or matri51 2 Enter A elements )or Matri51 ,1 1 2 > D A Elements o) Matri5,++++++, 1 2 > D A Elements o) Matri51++++++,1 1 2 > D A

Matri5 multiplication is not possi$le

/. Program to ind the sum o all the elements present in a 0agged arra- o 3 inner arra-s.
using System; class *agKarray { pu$lic static void Main() { int[][] *ag; int i9 *; int var; int sum = .; Console. rite!ine("Lagged 7rray"); Console. rite!ine("Enter no. o) ro(s "); int ro( = int.Parse(Console.%ead!ine()); *ag = ne( int[ro(][]; )or (i = .; i 6 ro(; i//) { Console. rite!ine("Enter total no. o) elements )or ro( " / (i / ,)); var = int.Parse(Console.%ead!ine()); *ag[i] = ne( int[var]; Console. rite!ine("Enter " / var / " elements"); )or (* = .; * 6 var; *//) { *ag[i][*] = int.Parse(Console.%ead!ine()); 0 Console. rite!ine(); 0 Console. rite!ine("<&e Lagged array is++++++-"); Console. rite!ine(); Console. rite!ine("*ag[" / ro( / "][]8 "); )or (i = .; i 6 ro(; i//) { )or (* = .; * 6 *ag[i].!engt&; *//) { Console. rite(" " / *ag[i][*]); sum = sum / *ag[i][*]; 0 Console. rite!ine(); 0 Console. rite!ine(); Console. rite!ine("7ddition o) all elements o) *agged array is 8" / sum); Console.%ead!ine(); 0 0 %un , Lagged 7rray Enter no. o) ro(s 2 Enter total no. o) elements )or ro( ,

2 Enter 2 elements , 1 2 Enter total no. o) elements )or ro( 1 > Enter > elements , 1 2 > Enter total no. o) elements )or ro( 2 D Enter D elements , 1 2 > D <&e Lagged array is++++++*ag[2][]8 , 1 2 , 1 2 > , 1 2 > D 7ddition o) all elements o) *agged array is 82,

11. Program to re+erse a string


using System; class revstr { pu$lic static void Main() { Console. rite!ine("Enter t&e string"); String str, = Console.%ead!ine(); String str1 = String.Empty; int str,Klen = str,.!engt&; )or (int i = str,Klen + ,; i -= .; i++) { str1 = str1 / str,[i]; 0 Console. rite!ine("%everse o) " / str, / " is " / str1); Console.%ead!ine(); 0 0 %un , Enter t&e string CS&arp !a$oratory %everse o) CS&arp !a$oratory is yrotaro$a! pra&SC %un 1 Enter t&e string ,12> %everse o) ,12> is >21,

11. Program usingTr-2 Catch and 3inall- blocks in C# to demonstrate error handling.
using System; class test { pu$lic static void Main() { int a = ,.9 $ = .9 c9 i; int[] arr = ne( int[2] { ,9 19 2 0; try { try { int d = arr[B]; 0 catc& (=nde5MutM)%angeE5ception e) { Console. rite!ine("EnEn" / e); Console. rite("EnEn7rray elements are++++-"); )or (i = .; i 6 arr.!engt&; i//) { Console. rite("En7rr [" / i / "]=" / arr[i]); 0 0 )inally { int d = arr[1]; Console. rite("EnEn<&e last element o) array = " / d); 0 c = a ' $; 0 catc& (Iivide?yNeroE5ception e) { Console. rite("EnEn" / e); 0 )inally { c = a ' ($ / 1); Console. rite("EnEnc = " / c); 0 Console.%ead!ine(); 0 0 %un , System.=nde5MutM)%angeE5ception8 =nde5 (as outside t&e $ounds o) t&e array. at test.Main() in C8EIocuments and SettingsE7dministratorE!ocal SettingsE7ppl ication IataE<emporary Pro*ectsEConsole7pplication,EProgram.cs8line ,1 7rray elements are++++-

7rr [.]=, 7rr [,]=1 7rr [1]=2 <&e last element o) array = 2 System.Iivide?yNeroE5ception8 7ttempted to divide $y Gero. at test.Main() in C8EIocuments and SettingsE7dministratorE!ocal SettingsE7ppl ication IataE<emporary Pro*ectsEConsole7pplication,EProgram.cs8line 1B c = D

12. 4esign a simple calculator using (witch (tatement in c#


using System; class cal { pu$lic static void Main() { Console. rite!ine("Simple Calculator"); Console. rite("EnEnter value )or a Et"); int a = int.Parse(Console.%ead!ine()); Console. rite("EnEnter value )or $ Et"); int $ = int.Parse(Console.%ead!ine()); int c&; do { Console. rite!ine(", 7ddition"); Console. rite!ine("1 Su$traction"); Console. rite!ine("2 Iivision"); Console. rite!ine("> Oraction"); Console. rite!ine("D Multiplication"); Console. rite!ine("A.E5it"); Console. rite!ine("Enter your c&oice"); c& = int.Parse(Console.%ead!ine()); int c; s(itc& (c&) { case ,8 c = a / $; Console. rite!ine("%esult 8 " / c); $reaF; case 18 c = a + $; Console. rite!ine("%esult 8 " / c); $reaF; case 28 c = a ' $; Console. rite!ine("%esult 8 " / c); $reaF; case >8 c = a P $; Console. rite!ine("%esult 8 " / c); $reaF; case D8 c = a 4 $; Console. rite!ine("%esult 8 " / c); $reaF; case A8 $reaF; de)ault8 Console. rite!ine("=nvalid c&oice HHH"); $reaF; 0 0 (&ile (c& H= A); 0 0

%un , Simple Calculator Enter value )or a Enter value )or $ , 7ddition 1 Su$traction 2 Iivision > Oraction D Multiplication A.E5it Enter your c&oice , %esult 8 D , 7ddition 1 Su$traction 2 Iivision > Oraction D Multiplication A.E5it Enter your c&oice 1 %esult 8 +, , 7ddition 1 Su$traction 2 Iivision > Oraction D Multiplication A.E5it Enter your c&oice 2 %esult 8 . , 7ddition 1 Su$traction 2 Iivision > Oraction D Multiplication A.E5it Enter your c&oice > %esult 8 1 , 7ddition 1 Su$traction 2 Iivision > Oraction D Multiplication A.E5it Enter your c&oice D %esult 8 A , 7ddition 1 Su$traction 2 Iivision > Oraction D Multiplication A.E5it Enter your c&oice A

1 2

13. 4emonstrate 5se o 6irtual and o+erride ke- words in C# with a simple program
using System; class student { pu$lic string name; pu$lic string college; pu$lic void getdata,() { Console. rite("Enter name8Et"); name = Console.%ead!ine(); Console. rite("Enter college8Et"); college = Console.%ead!ine(); 0 pu$lic virtual void display() { Console. rite!ine("#ame8 " / name); Console. rite!ine("College8 " / college); 0 0 class ugstudent 8 student { pu$lic int p&y; pu$lic int c&em; pu$lic int mat&; pu$lic void getdata1() { getdata,(); Console. rite("Enter p&y8Et"); p&y = int.Parse(Console.%ead!ine()); Console. rite("Enter c&em8Et"); c&em = int.Parse(Console.%ead!ine()); Console. rite("Enter mat&8Et"); mat& = int.Parse(Console.%ead!ine()); 0 pu$lic override void display() { Console. rite!ine("EnEn4444444QRS<QIE#<4444444EnEn"); Console. rite!ine("#ame8 " / name); Console. rite!ine("P&ysics8 " / p&y); Console. rite!ine("C&emistery8 " / c&em); Console. rite!ine("Mat&8 " / mat&); Console. rite!ine("College8 " / college); Console. rite!ine("EnEn4444444444444444444444444EnEn"); Console.%ead!ine(); 0 0 class pgstudent 8 student { pu$lic int im,; pu$lic int im1; pu$lic int im2; pu$lic int sem; pu$lic int t; pu$lic int )inal;

0 class researc&stud 8 student { pu$lic string researc&Ksu$; pu$lic void getdata>() { getdata,(); Console. rite("Enter researc& paper8Et"); researc&Ksu$ = Console.%ead!ine(); 0

pu$lic void getdata2() { getdata,(); Console. rite("Enter internal marFs,8Et"); im, = int.Parse(Console.%ead!ine()); Console. rite("Enter internal marFs18Et"); im1 = int.Parse(Console.%ead!ine()); Console. rite("Enter internal marFs28Et"); im2 = int.Parse(Console.%ead!ine()); Console. rite("Enter semester8Et"); sem = int.Parse(Console.%ead!ine()); 0 pu$lic void calculate() { int p = .; int s = .; int temp; int[] arr = ne( int[2] { im,9 im19 im2 0; )or (int i = .; i 6 2; i//) { temp = arr[i]; i) (temp - p) { s = p; p = temp; 0 i) (temp - s JJ temp 6 p) { s = temp; 0 0 t = p / s; )inal = t ' 1; 0 pu$lic override void display() { Console. rite!ine("EnEn4444444PRS<QIE#<4444444EnEn"); Console. rite!ine("#ame8 " / name); Console. rite!ine("=nternal ,8 " / im,); Console. rite!ine("=nternal 18 " / im1); Console. rite!ine("=nternal 28 " / im2); Console. rite!ine("O=nal =nternal MarFs8 " / )inal); Console. rite!ine("Semester8 " / sem); Console. rite!ine("College8 " / college); Console. rite!ine("EnEn4444444444444444444444444EnEn"); Console.%ead!ine(); 0

0 class test { pu$lic static void Main() { Console. rite!ine("EnEn++++++++++++++QR student+++++++++++++++"); ugstudent ug, = ne( ugstudent(); ug,.getdata1(); ug,.display(); pgstudent pg, = ne( pgstudent(); Console. rite!ine("EnEn++++++++++++++PR student+++++++++++++++"); pg,.getdata2(); pg,.calculate(); pg,.display(); Console. rite!ine("EnEn++++++++++++++%esearc& student+++++++++++++++"); researc&stud rs = ne( researc&stud(); rs.getdata>(); rs.display(); 0 0 %un , ++++++++++++++QR student+++++++++++++++ Enter name8 us&a Enter college8 $msce Enter p&y8 AC Enter c&em8 B@ Enter mat&8 CC 4444444QRS<QIE#<4444444 #ame8 us&a P&ysics8 AC C&emistery8 B@ Mat&8 CC College8 $msce 4444444444444444444444444 ++++++++++++++PR student+++++++++++++++ Enter name8 anand Enter college8 amc Enter internal marFs,8 BB Enter internal marFs18 DD Enter internal marFs28 AA

pu$lic override void display() { Console. rite!ine("EnEn4444444%ESE7%C3 S<QIE#<4444444EnEn"); Console. rite!ine("#ame8 " / name); Console. rite!ine("%esearc& paper8 " / researc&Ksu$); Console. rite!ine("College8 " / college); Console. rite!ine("EnEn4444444444444444444444444EnEn"); Console.%ead!ine(); 0

Enter semester8 > 4444444PRS<QIE#<4444444 #ame8 anand =nternal ,8 BB =nternal 18 DD =nternal 28 AA O=nal =nternal MarFs8 CC Semester8 > College8 amc 4444444444444444444444444 ++++++++++++++%esearc& student+++++++++++ Enter name8 Fumar Enter college8 c$pit Enter researc& paper8 net(orF 444444%ESE7%C3 S<QIE#<4444444 #ame8 Fumar %esearc& paper8 net(orF College8 c$pit 4444444444444444444444444

1$. 7mplement linked lists in C# using the e%isting collections name space.
using System; using System.Collections.Reneric; using System.<e5t; class !inFed!istIemo { pu$lic static void Main() { !inFed!ist6string- o$ = ne( !inFed!ist6string-(); int c&; do { Console. rite!ine("EnEnEt!inFed !ist =mplementationEnEn"); Console. rite!ine(",. 7dd at $eginnning"); Console. rite!ine("1. 7dd at end"); Console. rite!ine("2. %emove at $eginnning"); Console. rite!ine(">. %emove at end"); Console. rite!ine("D. 7dd at a speci)ied position"); Console. rite!ine("A. Iisplay t&e !=nFed !ist"); Console. rite!ine("C. Oind item"); Console. rite!ine("B. E5it"); Console. rite("Enter your c&oiceEt"); c& = int.Parse(Console.%ead!ine()); s(itc& (c&) { case ,8 Console. rite!ine("Enter t&e item to $e inserted at $eginning"); String item = Console.%ead!ine(); o$.7ddOirst(item); $reaF; case 18 Console. rite!ine("Enter t&e item to $e inserted at end"); String item, = Console.%ead!ine(); o$.7dd!ast(item,); $reaF; case 28 i) (o$.Count - .) { o$.%emoveOirst(); Iisplay(o$); 0 else Console. rite!ine("EnEt!inFed !ist is empty"); $reaF; case >8 i) (o$.Count - .) { o$.%emove!ast(); Iisplay(o$); 0 else Console. rite!ine("EnEt!inFed !ist is empty"); $reaF; case D8 Console. rite("Enter t&e positionEt"); int n = int.Parse(Console.%ead!ine()); i) (n - o$.Count SS n 6 ,)

else {

Console. rite!ine("EnEt=nvalid Position"); insert(o$9 n); Iisplay(o$);

0 private static void Iisplay(!inFed!ist6string- o$) { i) (o$.Count - .) { Console. rite!ine("EnEtContents o) t&e !inFed list"); )oreac& (o$*ect o$* in o$) { Console. rite(o$* / "Et"); 0 0 else Console. rite!ine("EnEt!inFed !ist is empty"); Console. rite!ine(); 0 private static void insert(!inFed!ist6string- o$9 int n) { !inFed!ist#ode6string- lin = o$.Oirst; )or (int i = .; i 6 n + ,; i//) lin = lin.#e5t; Console. rite!ine("Enter t&e item to $e inserted"); string item1 = Console.%ead!ine(); o$.7dd?e)ore(lin9 item1); 0 0

0 0 (&ile (c& H= C);

0 $reaF; case A8 Iisplay(o$); $reaF; case C8 Console. rite!ine("Enter item to $e searc&ed"); item = Console.%ead!ine(); !inFed!ist#ode6string- node, = o$.Oind(item); i) (node, == null) Console. rite!ine("Searc& is unsuccess)ull"); else Console. rite!ine("Searc& is success)ull"); Console.%ead!ine(); $reaF; case B8 $reaF; de)ault8 Console. rite!ine("EnEt=nvalid C&oice"); $reaF;

%un ,

!inFed !ist =mplementation ,. 7dd at $eginnning 1. 7dd at end 2. %emove at $eginnning >. %emove at end D. 7dd at a speci)ied position A. Iisplay t&e !=nFed !ist C. Oind item B. E5it Enter your c&oice , Enter t&e item to $e inserted at $eginning ,1 !inFed !ist =mplementation ,. 7dd at $eginnning 1. 7dd at end 2. %emove at $eginnning >. %emove at end D. 7dd at a speci)ied position A. Iisplay t&e !=nFed !ist C. Oind item B. E5it Enter your c&oice 1 Enter t&e item to $e inserted at end ,> !inFed !ist =mplementation ,. 7dd at $eginnning 1. 7dd at end 2. %emove at $eginnning >. %emove at end D. 7dd at a speci)ied position A. Iisplay t&e !=nFed !ist C. Oind item B. E5it Enter your c&oice , Enter t&e item to $e inserted at $eginning ,D !inFed !ist =mplementation ,. 1. 2. >. 7dd at 7dd at %emove %emove $eginnning end at $eginnning at end

D. 7dd at a speci)ied position A. Iisplay t&e !=nFed !ist C. Oind item B. E5it Enter your c&oice 1 Enter t&e item to $e inserted at end ,B !inFed !ist =mplementation ,. 7dd at $eginnning 1. 7dd at end 2. %emove at $eginnning >. %emove at end D. 7dd at a speci)ied position A. Iisplay t&e !=nFed !ist C. Oind item B. E5it Enter your c&oice A ,D Contents o) t&e !inFed list ,1 ,> ,B !inFed !ist =mplementation ,. 7dd at $eginnning 1. 7dd at end 2. %emove at $eginnning >. %emove at end D. 7dd at a speci)ied position A. Iisplay t&e !=nFed !ist C. Oind item B. E5it Enter your c&oice D Enter t&e position 2 Enter t&e item to $e inserted >D ,D Contents o) t&e !inFed list ,1 >D ,> ,B !inFed !ist =mplementation ,. 1. 2. >. D. A. C. B. 7dd at $eginnning 7dd at end %emove at $eginnning %emove at end 7dd at a speci)ied position Iisplay t&e !=nFed !ist Oind item E5it

Enter your c&oice ,1

Contents o) t&e !inFed list >D ,> ,B !inFed !ist =mplementation

,. 7dd at $eginnning 1. 7dd at end 2. %emove at $eginnning >. %emove at end D. 7dd at a speci)ied position A. Iisplay t&e !=nFed !ist C. Oind item B. E5it Enter your c&oice > ,1 Contents o) t&e !inFed list >D ,> !inFed !ist =mplementation ,. 7dd at $eginnning 1. 7dd at end 2. %emove at $eginnning >. %emove at end D. 7dd at a speci)ied position A. Iisplay t&e !=nFed !ist C. Oind item B. E5it Enter your c&oice C Enter item to $e searc&ed >D Searc& is success)ull

1'. Program to demonstrate abstract class and abstract methods in C#.


using System; a$stract class a$sclass { pu$lic int add(int n,9 int n1) { return n, / n1; 0 pu$lic a$stract int mul(int n,9 int n1); 0 class a$sderived 8 a$sclass { pu$lic override int mul(int n,9 int n1) '' a$stract met&od must $e implemented { return n, 4 n1; 0 pu$lic static void Main() { a$sderived cal = ne( a$sderived(); int added = cal.add(,.9 1.); int multiplied = cal.mul(,.9 1.); Console. rite!ine("7ddition 8 " / added / " Multiplication 8 " / multiplied); Console.%ead!ine(); 0 0 %un , 7ddition8 2. Multiplication8 1..

1). Program in C# to build a class which implements an inter ace which alread- e%ists.
using System; using System.Collections; pu$lic class Employee 8 =Compara$le { string name; int id; pu$lic Employee() { 0 pu$lic void getTalue() { Console. rite("EnEnter id8Et"); id = int.Parse(Console.%ead!ine()); 0 pu$lic Employee(string name9 int id) { t&is.name = name; t&is.id = id; 0 pu$lic int Compare<o(o$*ect o$*) ''int =Compara$le.Compare<o(o$*ect o$*) { Employee emp1 = (Employee)o$*; i) (t&is.id - emp1.id) return (,); i) (t&is.id 6 emp1.id) return (+,); else return (.); 0 pu$lic static =Comparer Sort?y#ame { get { return ((=Comparer)ne( Sort?y#ameClass()); 0 0 pu$lic static =Comparer Sort?y=d { get { return ((=Comparer)ne( Sort?y=dClass()); 0 0 pu$lic string display() ''pu$lic override string <oString() { return (name / "8" / id); 0

class Sort?y#ameClass 8 =Comparer { pu$lic int Compare(o$*ect o$*,9 o$*ect o$*1) { Employee emp, = (Employee)o$*,; Employee emp1 = (Employee)o$*1;

0 0

return (String.Compare(emp,.name9 emp1.name));

class Sort?y=dClass 8 =Comparer { pu$lic int Compare(o$*ect o$*,9 o$*ect o$*1) { Employee emp, = (Employee)o$*,; Employee emp1 = (Employee)o$*1; return (((=Compara$le)emp,).Compare<o(o$*1)); 0 0 class MainClass { pu$lic static void Main() { Employee[] arr = ne( Employee[>]; arr[.] = ne( Employee("I"9 ,,,); arr[,] = ne( Employee("P"9 1.); arr[1] = ne( Employee("N"9 >>); arr[2] = ne( Employee("7"9 ,1); 7rray.Sort(arr9 Employee.Sort?y#ame); -En"); Console. rite!ine("EnEnemployees is no( sorted $y name+++++++ )oreac& (Employee emp in arr) '' emp is an o$*ect Console. rite!ine("Employee8 {.0"9 emp.display()); 7rray.Sort(arr9 Employee.Sort?y=d); -En"); Console. rite!ine("EnEnemployees is no( sorted $y id+++++++++ )oreac& (Employee emp in arr) Console. rite!ine("Employee8 {.0"9 emp.display()); Employee myo$*ect = ne( Employee(); myo$*ect.getTalue(); int temp = 7rray.?inarySearc&(arr9 myo$*ect); i) (temp -= .) { Console. rite("EnSearc& is success)ul..."); Console. rite("EnPosition " / (temp / ,)); 0

0 else {

Console. rite("EnSearc& is unsuccess)ull..."); 0 Console.%ead!ine(); 0 0

%un , employees is no( sorted $y name+++++++Employee8 Employee8 Employee8 Employee8 78,1 I8,,, P81. N8>>

employees is no( sorted $y id+++++++++Employee8 Employee8 Employee8 Employee8 Enter id8 78,1 P81. N8>> I8,,, ,1

Searc& is success)ul... Position ,

1,. Program to illustrate the use o di erent properties in C#.


using System; class Myclass { private int 5; private static int y; ''static mem$er pu$lic Myclass() '' (orFs (it& read only property { 5 = ,..; 0 pu$lic int U ''general property { get { return 5; 0 set { 5 = value; 0 0 pu$lic int V ''read only property { get { return 5; 0 0 pu$lic int N ''(rite only property { set { 5 = value; 0 0 pu$lic static int P ''static property { get { return y; 0 set { y = value; 0 0 pu$lic int display() ''(orFs (it& (rite only property { return 5; 0 0 a$stract class Myclass, { pu$lic int 5; pu$lic a$stract int ; ''a$stract property

{ 0 0

get; set;

class concrete 8 Myclass, { pu$lic override int ; { get { return 5; 0 set { 5 = value; 0 0 0 class test { pu$lic static void Main() { Console. rite("EnEnReneral Property++++++++++-"); Myclass mc, = ne( Myclass(); mc,.U = ,.; ''set is invoFed; int val = mc,.U; ''get is invoFed Console. rite("EnEnPrivate mem$er 5 8 " / val); Console. rite("EnEnEn%ead+Mnly Property++++++++++-"); Myclass mc1 = ne( Myclass(); Console. rite!ine("EnEnPrivate mem$er 5 8 " / mc1.V); Console. rite("EnEnEn rite+Mnly Property++++++++++-"); Myclass mc2 = ne( Myclass(); mc2.N = 1.; Console. rite!ine("EnEnPrivate mem$er 5 8 " / mc2.display()); Console. rite("EnEnEnStatic Property++++++++++-"); Myclass.P = 1..; ''identi)ied $y type class val = Myclass.P; Console. rite!ine("EnEnPrivate sattic mem$er y 8 " / val); Console. rite("EnEnEn7$stract Property++++++++++-"); concrete mc> = ne( concrete(); mc>.; = ,...; ''set is invoFed; val = mc>.;; ''get is invoFed Console. rite("EnEnPrivate mem$er 5 8 " / val); Console.%ead!ine();

0 0

%un , Reneral Property++++++++++Private mem$er 5 8 ,. %ead+Mnly Property++++++++++Private mem$er 5 8 ,..

rite+Mnly Property++++++++++Private mem$er 5 8 1.

Static Property++++++++++Private sattic mem$er y 8 1..

7$stract Property++++++++++Private mem$er 5 8 ,...

1.. 4emonstrate arra-s o inter ace t-pes with a C# program.


using System; pu$lic inter)ace s&ape { void area(); 0 pu$lic class circle 8 s&ape { pu$lic void area() { Console. rite!ine("Calculating area o) circle."); Console. rite("Enter t&e radius8 "); )loat radius = )loat.Parse(Console.%ead!ine()); Console. rite!ine("7rea = {.0"9 2.,> 4 radius 4 radius); 0 0 pu$lic class s:uare 8 s&ape { pu$lic void area() { Console. rite!ine("Calculating area o) s:uare."); Console. rite("Enter t&e side8 "); )loat side = )loat.Parse(Console.%ead!ine()); Console. rite!ine("7rea= {.0"9 side 4 side); 0 0 class Program { static void Main(string[] args) { s&ape[] )indarea = ne( s&ape[1];''{ne( circle()9ne( s:uare()0; )indarea[.] = ne( circle(); )indarea[,] = ne( s:uare(); )or (int i = .; i 6 )indarea.!engt&; i//) )indarea[i].area(); Console.%ead!ine(); 0 0 %un , Calculating area o) circle. Enter t&e radius8 2 7rea = 1B.1A Calculating area o) s:uare. Enter t&e side8 D 7rea= 1D

PART B Sample form

Pro/osed 0i2a 1uestions 1. Name the building blocks of .NET rame!ork ". #hat is .NET frame!ork$ %. State at least fi&e most important highlights of '( language. ). State significant differences bet!een '** and '( +. ,o! is '( better than -a&a$ .. State some features of '** that ha&e not been incorporated into '(. /. State some features that are uni0ue to '( language. 1. #hat is '2R$ 3. #hat is 'TS$ 14. #hat is '2S$ 11. #hat is managed code$ 1". 2ist some of the important ser&ices the rame!ork Base 'lasses can offer to the users. 1%. 2ist the languages supported b5 the .NET rame!ork. 1). #h5 do !e use the using directi&e in a '( program$ 1+. #hat are the steps in&ol&ed in implementing an application program in '($ 1.. #hat is bo6ing and unbo6ing$ 1/. #hat do 5ou mean b5 implicit con&ersion$ 11. #hat do 5ou mean b5 e6plicit con&ersion$ 13. 7ention the different t5pes of operators a&ailable in '(. "4. E6plain the usage of foreach statement in '(. "1. E6plain the difference bet!een break and continue statement. "". #hat is a label$ ,o! and !hen a label is used in a program$ "%. 2ist the different access modifiers a&ailable. "). #hat are the different t5pes of parameters a&ailable$ "+. State the difference bet!een ref and out parameters. ".. #hat are parameter arra5s$ #hat are the restrictions in declaring parameter arra5s$ "/. State the differences bet!een rectangular arra5 and 8agged arra5. "1. ,o! does an arra5 of Arra52ist class differ from an arra5 of Arra5 class$ "3. State some of the methods a&ailable in Arra52ist class. %4. #hat is the difference bet!een 7utable and 9mmutable string$ %1. #hat is a &erbatim string$ %". #hen do 5ou use the StringBuilder class$ %%. #hat are Regular E6pressions$ ,o! do 5ou use them$ %). 7ention the differences bet!een classes and structs. %+. 7ention the important characteristics of a constructor. %.. #h5 do !e usuall5 declare constructors as public$ %/. #hat is a cop5 constructor$ %1. #hat is a propert5$ E6plain the different t5pes. %3. #hat is an inde6er$ #hat is it used for$ )4. ,o! does an inde6er differ from a propert5 in terms of implementation$ )1. #hat are the different t5pes of inheritance$ )". #hat is the difference bet!een o&erloading and o&erriding$

)%. State the characteristics of abstract classes and abstract methods. )). #hen do !e use sealed classes$ )+. #hat is a &irtual method$ ).. #hat is pol5morphism$ )/. #hat is an interface$ )1. #hat are the ma8or differences bet!een a class and an interface$ )3. #hat are the similarities bet!een a class and an interface$ +4. #hat is e6plicit interface implementation$ #hen it is used$ +1. :istinguish bet!een an abstract class and an interface. +". 'an an abstract class implement interfaces$ 9f 5es; ho! are the interface methods implemented$ +%. Name some of the built<in interfaces a&ailable. +). #hat is 9disposable interface$ E6plain its usage. ++. #hat is ='$ #hat are the different generations a&ailable$ +.. :ifferentiate bet!een 9comparable and9'omparer interfaces. +/. =i&e the usage of 9enumerator interface. +1. #hat are the comparison operators$ ,o! are the5 o&erloaded$ +3. #hat is a delegate$ #hat is it used for$ .4. =i&e the s5nta6 of a delegate declaration. .1. #hat are the modifiers that can be applied to a delegate$ .". #hat are the places a delegate can be defined in a program$ .%. #hat are the re0uirements of a delegate method$ .). #hat is a multicast delegate$ State the characteristics. .+. #hat do 5ou mean b5 As5nchronous delegates$ #h5 is it re0uired$ ... #hat is an e&ent$ =i&e the s5nta6 of an e&ent declaration. ./. #hat is an e&ent handler$ ,o! is it designed$ .1. #hat is numeric formatting$ .3. =i&e the general format of the standard numerical format. /4. #hat is an e6ception$ =i&e some e6amples. /1. :escribe the tasks in&ol&ed in handling e6ceptions. /". 2ist atleast four e6ceptions that occur commonl5 in '( programs. /%. #hat happens !hen a tr5 block is neither follo!ed b5 a catch block; nor b5 a finall5 block$ /). :istinguish bet!een the parameter less catch and the catch >E6ception e? statements. /+. #hat is the purpose of using a finall5 block$ =i&e some e6amples. /.. #hen do !e use a parameterless catch handler$ //. #h5 is a proper ordering of catch blocks necessar5 in '($ /1. #hat is an Assembl5$ /3. :ifferentiate bet!een 7anifest and 7etadata. 14. :ifferentiate bet!een ph5sical and logical &ie! of an assembl5. 11. =i&e the usage of checked and unchecked ke5!ord. 1". =i&e the usage of unsafe ke5!ord. 1%. :ifferentiate bet!een pri&ate assembl5 and shared assembl5. 1). E6plain the usage of 9cloneable interface. 1+. :istinguish bet!een :eep cop5 and shallo! cop5.

Das könnte Ihnen auch gefallen