You are on page 1of 45

Q:1 write the program to use of Substring?

Ans: using System; class A { static void Main(string[] b1) { string a = "kulvir singh"; string b; b = a.Substring(3,6); Console.WriteLine(b); Console.ReadLine(); } }

OUTPUT:

Q:2 write the program of index of ()fuction? Ans: using System; class A { static void Main(string[] b1) { string a = "framework"; int b; b = a.IndexOf(a); Console.WriteLine(b); b = a.IndexOf("a",3); Console.WriteLine(b); Console.ReadLine(); } }

OUTPUT:

Q3:write the program uses of compare to() function? using System; class A { static void Main(string[] b1) { string a = "framework"; string b = "framework"; int c; c = a.CompareTo(b); Console.WriteLine(c); Console.ReadLine(); } } OUTPUT:

Q4:write the program to uses of Equals()function? Ans: using System; class A { static void Main(string[] b1) { string a = "framework"; string b = "framework"; int c; c = a.Equals(b); Console.WriteLine(c); Console.ReadLine(); } }

Q5:Write the program to uses of Replace() function? Ans: using System; class A { static void Main(String[] b1) { string a = "framework"; string b; b = a.Replace("o", "e"); Console.WriteLine(b); Console.ReadLine(); } }

OUTPUT:

Q6:write the program to use of Insert() function? Ans: using System; class A { static void Main() { string a = "c shrp "; string b; b = a.Insert(4, "java"); Console.WriteLine(b); Console.ReadLine(); } }

OUTPUT:

7:write the program to use the This function ? Ans: using System; class A { int a,b; void f1(int x,int y) { a=x; b=y; } void f2(int a,int b) { this.a=a; this.b=b; } void f3() {

int c; c=a+b; Console .WriteLine (c); } static void Main (string []b1) { A a1=new A(); a1.f1(10,20); a1.f3(); a1.f2(30,40); a1.f3(); Console.ReadLine(); } } OUTPUT:

Q8:write the program to use the This function? Ans: using System; class A { int a,b,c; void f1() { int a = 10, b = 40; this.a=a; this.b=b; } void f2() { c = a + b; Console.WriteLine(c); } static void Main () { A a1 = new A(); a1.f1(); a1.f2(); Console.ReadLine(); } }

OUTPUT:

Q9:write the program to function overloading? Ans: using System; class A { void f1() { Console.WriteLine("f1 method"); } void f1(int x) { Console.WriteLine("f1 method" + x); } void f1(int x, int y) { Console.WriteLine("f1 method" + x + y); }

static void Main () { A a1=new A (); a1.f1(); a1.f1(10); a1.f1(10); a1.f1(20 , 30); Console .ReadLine(); } }

OUTPUT:

Q10:write the program to fuction overloading? Ans: using System; class A { public void f1() { Console.WriteLine("f1 method of A"); } public void f2() { Console.WriteLine("f2 method of A"); } class B : A { void f1() { Console.WriteLine("f1 method of B"); } void f2() { Console.WriteLine("f2 method of B"); } } static void Main() { B b1 = new B(); b1.f1(); b1.f2(); Console.ReadLine(); } }

OUTPUT:

Q11:write the program to array? Ans: using System; class A { static void Main() { int[,,]a=new int [2,2,3]; int i,j,k; Console .WriteLine ("enter the array"); for (i=0;i<=1;i++) { for(j=0;j<=1;j++) { for(k=0;k<=2;k++) {

a[i,j,k]=int.Parse (Console .ReadLine ()); Console.WriteLine (a[i,j,k]); } } } Console .ReadLine(); } }

OUTPUT:

Q:12 write the program to copy constructor? Ans: using System; class A { int a, b, c; A() { a = 10; b = 20; } A(int x) { a=b=x; } A(int x,int y) { a=x; b=y; } void output() { c = a + b; Console.WriteLine(c); } static void Main() { A a1=new A(); A a2=new A(40); A a3=new A(10,20); a1.output (); a2.output (); a3.output (); Console.ReadLine (); } }

OUTPUT:

Q13:example of constructor? Ans: using System; class A { int a,b, c; A() { a=10; b=20; } A(int x) { a=b=x; } A(int x,int y)

{ a=x; b=y; } void output() { c=a+b; Console .WriteLine (c); } static void Main(string []aig) { A a1=new A(); A a2=new A(40); A a3=new A(30,60); a1.output (); a2.output (); a3.output (); Console.ReadLine(); } }

OUTPUT:

Q14: exemple of constructor? Ans: using System; class A { int a,b, c; A() { a=10; b=20; } A(int x) { a=b=x; } A(int x,int y) { a=x; b=y; } A(A a1) { a = a1.a; b = a1.b; } void output() { Console .WriteLine (a); Console.WriteLine(b); } static void Main(string []aig) { A a1=new A(); A a2=new A(40); A a3=new A(50,60); A a4 = new A(a1); A a5 = new A(a2); A a6 = new A(a3); a1.output (); a2.output (); a3.output ();

a4.output(); a5.output(); a6.output(); Console.ReadLine(); } }

OUTPUT:

Q15: Write the program object is locate memory space for all the non static data memory avalible in class? Ans: using System; class A { int a=10,b=20, c=30; void f1() { Console.WriteLine(a); Console.WriteLine(b); Console.WriteLine(c); } static void Main(string []aig) { A a1=new A(); Console.WriteLine(sizeof (int)); Console.WriteLine(sizeof(decimal)); Console.ReadLine(); } }

OUTPUT:

Q15:write the program of defult constructor? Ans: using System; class A { protected internal A() { Console.WriteLine("defult constructor"); } } class B { static void Main(string[]a) { A a1=new A();

Console.ReadLine(); } }

OUTPUT:

Q16: example of single inheritance? Ans: using System; class A { internal void f1() { Console.WriteLine("f1 method of class A"); } }

class B : A { void f2() { Console.WriteLine("f2 method of class B"); } static void Main(string[]a) { B b1=new B(); b1.f1(); b1.f2(); Console.ReadLine(); } }

OUTPUT:

Q17: example of multi inheritance. Ans:

using System; class A { internal void f1() { Console.WriteLine("f1 method of class A"); } } class B : A { internal void f2() { Console.WriteLine("f2 method of class B"); } } class C : B { internal void f3() { Console.WriteLine("f3 method of class C"); } static void Main(string[] a) { C c1 = new C(); c1.f1(); c1.f2(); c1.f3(); Console.Read(); } }

OUTPUT:

Q18: example of hierarchal inheritance . Ans:

using System; class A { internal void f1() { Console.WriteLine("f1 method of class A"); } } class B : A { internal void f2() { Console.WriteLine("f2 method of class B");

} } class C : A { internal void f3() { Console.WriteLine("f3 method of class C"); } static void Main(string[] a) { B b1 = new B(); b1.f1(); b1.f2(); C c1 = new C(); c1.f1(); c1.f3(); Console.Read(); } } OUTPUT:

Q19: Ans:

Exemple of inner class?

using System; class A { public class B { public static void f1() { Console.WriteLine("f1 method"); } public void f2() { Console.WriteLine("f2 Method"); } } public void f3() { Console.WriteLine("f3 method"); } } class C { static void Main(string[] args) { A.B b1 = new A.B(); b1.f2(); A.B.f1(); A a = new A(); a.f3(); Console.ReadLine(); } }

OUTPUT:

Q20:Example of call by value ,call by refrens? Ans: using System; class A { void Swap(ref int a,ref int b) { int c; c = a; a = b; b = c; Console.WriteLine(a + " " + b); } static void Main(string[] args) { int x,y;

Console.WriteLine("enter the two integer"); x = int.Parse(Console.ReadLine()); y = int.Parse(Console.ReadLine()); A a1=new A(); a1.Swap(ref x,ref y); Console.WriteLine(x+" "+y); Console.Read(); } }

OUTPUT:

Q21:example of is Keyword? Ans: using System; class A { } class B : A { } class C { static void Main(string[] args) { A a1 = new A(); B b1 = new B(); if (a1 is A) { Console.WriteLine("a1 is object A B"); if (b1 is B) { Console.WriteLine("b is a object of B"); if (b1 is A) { Console.WriteLine("b1 contain the feature of A"); if (a1 is B) { Console.WriteLine("contain the featureof B"); } } } } Console.ReadLine(); } }

OUTPUT:

Q22: example of Linked List class. Ans: using System; using System.Collections.Generic; class A { static void Main(string[] a) { LinkedList<int> b = new LinkedList<int>(); b.AddFirst(10); b.AddLast(20); b.AddLast(5); int i; foreach (int x in b) { Console.WriteLine(x);

} Console.ReadLine(); } }

OUTPUT:

Q23:Example of 2 D Indexer? Ans: using System; class A { int a; int this[int x, int y] { get { return a; } set { a = value; } } static void Main() { A a1=new A(); int i,j; for (i=0;i<=1;i++) { for (j=0;j<=1;j++) { a1[i,j]=i+j; Console .WriteLine(a1[i,j]); Console .ReadLine(); } } } }

OUTPUT:

Q24: example of stack in .net framework? Ans: using System; using System.Collections; class A { static void Main(string[] a) { Stack S = new Stack(); S.Push("10"); S.Push("20"); S.Push("30"); foreach (string x in S) { Console.WriteLine(x);

Console.WriteLine(S.Pop()); Console.ReadLine(); } } }

OUTPUT:

Q25: Example of Queue In .net FrameWork? Ans: using System; using System.Collections; class A { static void Main(string[] a) { Queue q = new Queue(); q.Enqueue("10"); q.Enqueue("20"); q.Enqueue("30"); foreach (string x in q) Console.WriteLine(x); q.Dequeue(); foreach (string x in q) Console.WriteLine(x); Console.ReadLine(); } } OUTPUT:

Q26: Create an application to input a string at runtime and copy into another strig. Ans: using System; class A { static void Main(string[] args) { string a, b; Console.WriteLine("Enter a string: "); a = Console.ReadLine(); b = a; Console.WriteLine(b); Console.Read(); } }

OUTPUT:

Q27: Create an application to input two strings and the two strings are equal or not. Ans: using System; class A { static void Main(string[] args) { string a, b; Console.WriteLine("Enter a string: "); a = Console.ReadLine(); b = Console.ReadLine(); if (a.CompareTo(b) == 0) Console.WriteLine("Equal"); else Console.WriteLine("not equal"); Console.Read(); } } OUTPUT:

Q28: Write a program of threading. Ans: using System; using System.Threading; class A { string a; A(string b) { a = b; } public void run() { Console.WriteLine(a); } static void Main() { A a1 = new A("Thread1"); A a2 = new A("Thread2"); A a3 = new A("Thread3"); Thread t1 = new Thread(a1.run); Thread t2 = new Thread(a2.run); Thread t3 = new Thread(a3.run); t1.Start(); t2.Start(); t3.Start(); Console.Read(); } }

OUTPUT:

Q29: example of property ? Ans: using System; class A { int a; int abc { get { return a; } set { a = value; } } static void Main()

{ A a1 = new A(); a1.a = 10; Console.WriteLine(a1.a); Console.ReadLine(); } }

OUTPUT:

Q30:Example of Deleqate? Ans: using System; delegate void abs(string a); class A { void f1(string x) { Console.WriteLine(x); } void f2(string y) { Console.WriteLine(y); } static void Main() { A a1 = new A(); abs a; a = a1.f1; a("itm"); a = a1.f2; a("graphic"); Console.Read(); } }

OUTPUT:

Q31:Example of interface in .net framework? Ans: using System; interface A { void f1(); void f2(); } class B:A { public void f1() { Console .WriteLine("f1 method of class A"); } public void f2() { Console .WriteLine ("f2 method of class A"); } static void Main () {

B b1=new B(); b1.f1(); b1.f2(); Console .ReadLine (); } } OUTPUT:

Q32: Example of interface? Ans: using System; interface A { void f1(); void f2(); } interface B {

void f3(); void f4(); } class C:B,A { public void f1() { } public void f2() { Console .WriteLine ("f2 method of class A"); } public void f3() { Console.WriteLine("f3 method of class A"); } public void f4() { } static void Main () { C c1=new C(); c1.f1(); c1.f2(); c1.f3(); c1.f4(); A a1; a1 = c1; a1.f1(); a1.f2(); B b1; b1 = c1; b1.f3(); b1.f4(); Console.ReadLine(); } }

OUTPUT:

You might also like