You are on page 1of 22

C# Practicals

Practical no-24
using System; class Rect { int len; int bre; public Rect(int x,int y) { len=x; bre=y; } public Rect(int x) { len=bre=x; } public Rect(Rect r) { len=r len; bre=r bre; } !Rect() { "onsole #rite$ine(%&estructor is calle' } public int (rea() { return(len)bre); } }

%);

Coded by Pravin A.Dherange

C# Practicals

class Prac24 { public static *oi' +ain() { Rect r,=ne- Rect(,.,2.); Rect r2=ne- Rect(,.); Rect r/=ne- Rect(r,); "onsole #rite$ine(%(rea o0 rectangle1 %2r, (rea()); "onsole #rite$ine(%(rea o0 s3uare1 %2r2 (rea()); "onsole #rite$ine(%(rea o0 rectangle1 %2r/ (rea()); } }

Coded by Pravin A.Dherange

C# Practicals

4utput-

Coded by Pravin A.Dherange

C# Practicals

Practical no-25
using System; using System 6ext; using System 6ext Regular7xpressions; class pr25 { public static *oi' +ain() { String s=%(mar, (8bar, (nt9ony are 0rien's%; Regex x=ne- Regex(% :, %); String;uil'er str=ne- String;uil'er(); int count=,; 0oreac9(String st in x Split(s)) { str (ppen'<ormat(%{.}1 {,}=n%,count22,st); } "onsole #rite$ine(str); } }

Coded by Pravin A.Dherange

C# Practicals

4utput-

Coded by Pravin A.Dherange

C# Practicals

Practical no-2>
() ?nary operator o*erloa'ing "o'e1using System; class space { int x, y,@; public space() { } public space(int a,int b,int c) { x=a; y=b; @=c; } public *oi' 'isplay() { "onsole #rite$ine(x); "onsole #rite$ine(y); "onsole #rite$ine(@); "onsole #rite$ine(); } public static space operator -(space s) { space ss = ne- space(); ss x = -s x; ss y = -s y; ss @ = -s @; return ss; } } class test, { public static *oi' +ain() { space s = ne- space(,.,2.,-/.); s 'isplay(); s = -s; s 'isplay(); } }

Coded by Pravin A.Dherange

C# Practicals

4utput-

Coded by Pravin A.Dherange

C# Practicals

;) ;inary operator o*erloa'ing "o'e1using System; class complex { int x, y,@; public complex() { } public complex(int a,int b,int c) { x=a; y=b; @=c; } public *oi' 'isplay() { "onsole #rite$ine(x); "onsole #rite$ine(y); "onsole #rite$ine(@); "onsole #rite$ine(); } public static complex operator 2(complex c,,complex c2) { complex c/ = ne- complex(); c/ x = c, x2c2 x; c/ y = c, y2c2 y; c/ @ = c, @2c2 @; return (c/); } } class test2 { public static *oi' +ain() { complex obA, = ne- complex(,.,2.,/.); complex obA2 = ne- complex(2.,/.,4.); complex obA/ = obA,2obA2; obA, 'isplay(); obA2 'isplay();
Coded by Pravin A.Dherange

C# Practicals

obA/ 'isplay(); } }

4utput-

Coded by Pravin A.Dherange

C# Practicals

Practical no-2B
using System; using System 6ext Regular7xpressions; using System 6ext; class *ector { int x,y,@; public *ector() {} public *ector(int a, int b, int c) { x = a; y = b; @ = c; } public o*erri'e String 6oString() { return(%x=%2x2%,y=%2y2%,@=%2@); } public static bool operator==(*ector *, , *ector *2) { i0 (*, x == *2 x CC *, y == *2 y CC *, @ == *2 @) { return (true); } else { return(0alse); } } public static bool operatorD=(*ector *,, *ector *2) { return (D(*, == *2)); } }

Coded by Pravin A.Dherange

C# Practicals

class compare { public static *oi' +ain() { *ector u, = ne- *ector (,,/,/); *ector u2 = ne- *ector (,,2,/); i0 (u, == u2) { "onsole #rite$ine(%;ot9 obAects are e3ual%); "onsole #rite$ine(u, 6oString()); "onsole #rite$ine(u2 6oString()); } else { "onsole #rite$ine(%4bAects are not e3ual%); "onsole #rite$ine(u, 6oString()); "onsole #rite$ine(u2 6oString()); } } }

Coded by Pravin A.Dherange

C# Practicals

4utput-

Coded by Pravin A.Dherange

C# Practicals

Practical no-2E () &elegate "o'e1using System; 'elegate int (rit9op(int a,int b); class +at94peration { public static int (''(int a,int b) { return(a2b); } public static int Sub(int a,int b) { return(a-b); } }

class 'emo { public static *oi' +ain() { (rit9op operation,=ne- (rit9op(+at94peration (''); (rit9op operation2=ne- (rit9op(+at94peration Sub); int result,=operation,(2..,F.); int result2=operation2(2..,/.); "onsole #rite$ine(%(''ition1 %2result,); "onsole #rite$ine(%Subtraction1 %2result2); } }

Coded by Pravin A.Dherange

C# Practicals

4utput-

Coded by Pravin A.Dherange

C# Practicals

;) +ulticast &elegate "o'e1using System; 'elegate *oi' +'elegate(); class 4peration { public static *oi' Print() { "onsole #rite$ine(%Ge- &el9i%); } public static *oi' &isplay() { "onsole #rite$ine(%Ge- Hor8%); } }

class 'emo { public static *oi' +ain() { +'elegate m,=ne- +'elegate(4peration Print); +'elegate m2=ne- +'elegate(4peration &isplay); +'elegate m/=m,2m2; +'elegate m4=m22m,; +'elegate mF=m/-m2; m/(); m4(); mF(); } }

Coded by Pravin A.Dherange

C# Practicals

4utput-

Coded by Pravin A.Dherange

C# Practicals

Practical no-/.
using System; public 'elegate *oi' 7'el(String str); class 7*ent"lass { public e*ent 7'el status; public *oi' 6rigger7*ent() { i0(status D= null) { status(%7*ent 6riggere'%); } } }

class 7*ent6est { public static *oi' +ain() { 7*ent"lass ec = ne- 7*ent"lass(); 7*ent6est et = ne- 7*ent6est(); ec status 2= ne- 7'el(et "atc97*ent); ec 6rigger7*ent(); } public *oi' "atc97*ent(String s) { "onsole #rite$ine(s); } }

Coded by Pravin A.Dherange

C# Practicals

4utput-

Coded by Pravin A.Dherange

C# Practicals

Practical no-/,
using System; class &emo { public static *oi' +ain() { "onsole #rite$ine(%Stan'ar' <ormating%); "onsole #rite$ine(%"urrency <ormat = {.1c}%,4F5> BEE); "onsole #rite$ine(%"urrency <ormat = {.1c}%,-4F5> BEE); "onsole #rite$ine(%Integer <ormat = {.1&}%,/4F5>); "onsole #rite$ine(%Integer <ormat = {.1&B}%,4F5>); "onsole #rite$ine(%7xponential <ormat = {.17}%,/4F5); "onsole #rite$ine(%7xponential <ormat = {.17B}%,/4F5); "onsole #rite$ine(%Gumber <ormat = {.1G}%,/4F5>BE); "onsole #rite$ine(%Gumber <ormat = {.1GB}%,/4F5>BE); "onsole #rite$ine(%<ixe' <ormat = {.1<}%,/4F5); "onsole #rite$ine(%<ixe' <ormat = {.1<B}%,/4F5); "onsole #rite$ine(%"ustom <ormating%); "onsole #rite$ine(%"ustom place9ol'er= {.1....}%,,2/); "onsole #rite$ine(%Jero place9ol'er= {.1....}%,,2/); "onsole #rite$ine(%Space place9ol'er= {.1KKKK}%,,2/); "onsole #rite$ine(%"ombo place9ol'er={.1KKK ....}%,,2 /22F5); "onsole #rite$ine(%Space place9ol'er= {.1KK,KKK ..}%,,2/,2F4 2F5); "onsole #rite$ine(%Per place9ol'er= {.1..L}%,. 2/);

} }

Coded by Pravin A.Dherange

C# Practicals

4utput-

Coded by Pravin A.Dherange

C# Practicals

Practical no-/2
using System; class +y7xception 1 7xception { public +y7xception (String msg)1 base (msg) {} public +y7xception() {} public +y7xception (String msg, 7xception inner)1 base(msg, inner) { } } class 6est7xception { public static *oi' +ain() { int x = F; int y = ,...; try { 0loat @ = (0loat)xM(0loat)y; i0 (@N. .,) { t9ro- ne- +y7xception (%numer is too small%); } } catc9(+y7xception 7) { "onsole #rite$ine (%7xception "aug9t%); "onsole #rite$ine (7 +essage); } } }

Coded by Pravin A.Dherange

C# Practicals

4utput-

Coded by Pravin A.Dherange

You might also like