Skip to main content

Posts

Showing posts from August 13, 2014

Static Class in C sharp #

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication14 {public static class math  {      public static int big(int a, int b)     {         if (a > b)             return a;         else             return b;      }      public static int pow(int a, int b)      {int i=0,pow=1;      for (i = 0; i < b; i++)          pow = pow * a;      return pow;      }   }     class Program     {         static void Main(string[] args)         {             Console.WriteLine("Big is :"+math.big(100,102));             Console.WriteLine("Power is: " + math.pow(2, 4));             Console.ReadKey();         }     } }

Sealed Class in C sharp #

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication13 {     sealed class x     {       public   int x2, y2, z2;       public x()       {           x2 = 123;           y2 = 456;           z2 = 789;       }         public void display()         {             Console.WriteLine("Display 1");         }         public void print()         { Console.WriteLine("Print 1"); }             }                 class Program     {         static void Main(string[] args)         {             x ob = new x();             Console.WriteLine(ob.x2);           ob.display();           Console.Read();         } } }

Partial class in c sharp #

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication12 {     partial class x     {         public void display()         {             Console.WriteLine("Display 1");         }         public void print()         { Console.WriteLine("Print 1"); }     }     partial class x     {         public void display2()         { Console.WriteLine("Display 2"); }         public void print2()         { Console.WriteLine("Print 2"); }     }     class Program     {         static void Main(string[] args)         {             x ob = new x();             ob.display();             ob.display2();             ob.print();             ob.print2();             Console.Read();         }     } }