Skip to main content

Posts

Showing posts from August 29, 2014

Constructors in inheritance in c sharp #

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace My {     class abc     {        public abc()         {             Console.WriteLine("this is a base constructor");         }        public  void display()         {             Console.WriteLine("this is a base");         }     }     class abc2 : abc     {        public abc2():base()         {         }        public   void display()         {             base.display();             Console.WriteLine("this is a derived");         }     }     class MyClass     {         static void Main(string[] args)         {             abc2 ob = new abc2();             ob.display();             Console.Read();         }     } }

Calling base class method function from derived class having same name in c sharp #

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace My {     class abc     {        public  void display()         {             Console.WriteLine("this is a base");         }     }     class abc2 : abc     {        public   void display()         {             base.display();             Console.WriteLine("this is a derived");         }     }     class MyClass     {         static void Main(string[] args)         {             abc2 ob = new abc2();             ob.display();             Console.Read();         }     } }

Property in c sharp #

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace My {       class MyClass     {         int id { get; set; }         string name { get; set; }         static void Main(string[] args)         {             MyClass ob = new MyClass();             ob.id = 101;             Console.WriteLine(ob.id);             Console.Write(ob.name);             // it will produce blank or null value             ob.name = "anuj";             Console.WriteLine(ob.name);                         Console.Read();                 }     } }

Multicast Delegate in C sharp #

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace My {   //  public delegate int del(int a, int b);     public delegate void del(int a,int b);     class MyClass     {      //static  int sum (int a, int b)     static void sum(int a,int b)       {           Console.WriteLine((a+b));            // return (a+b);         }       //  static  int minus (int a, int b)     static void minus(int a, int b)           {        Console.WriteLine((a-b));           //  return (a-b);         }         MyClass(int y)         {         }         static void Main(string[] args)         {             del ob = new del(sum);         //    Console.WriteLine("delegate received "+ob(45, 40));             ob(45, 40);             ob += new del(minus);            // Console.WriteLine("delegate received " + ob(45, 40));             ob(45, 40);             ob -= new del(minus);            // Console.WriteLine(

Sorting array in c sharp # with use of functions

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace My {     class MyClass     {         MyClass(int y)         {         }         static void Main(string[] args)         {             int[] arr = { 1, 9, 8, 7, 5, 6, 8, 1, 2, };             foreach (int n in arr)             {                 Console.Write(n+" ");             }             Array.Sort(arr);             Console.WriteLine();             foreach (int n in arr)             {                 Console.Write(n + " ");             }                         Array.Reverse(arr);             Console.WriteLine();             foreach (int n in arr)             {                 Console.Write(n + " ");             }                         Console.Read();                     }     } }