static void Main(string[] args) { Console.WriteLine("This is old class"); OldClass m = new OldClass(); m.Method1(); m.Method2(); }
static void Main(string[] args) { ///Method Extension on classes OldClass old = new OldClass(); old.Method1(); old.Method2(); old.Method3(); old.Method4(4); ///Method Extension on structure int n = 5; long f = n.Factorial(); Console.WriteLine("Factorial of {0} is {1}", n, f); int a = 9, b = 9, sum = 0; sum = sum.AddAB(a, b); Console.WriteLine("{0} + {1} = {2}", a, b, sum); ///Method Extension on sealed classes string s = " mY name is Jitu "; Console.WriteLine("Orginal String : " + s); string ps = s.ToProper(); Console.WriteLine("Proper Case : " + ps); /* * ///Have a look of these Trim() * string p = " jitu is "; * Console.WriteLine(p.Trim()); * Console.WriteLine(p.TrimStart()); * Console.WriteLine(p.TrimEnd()); */ }
internal static void Method4(this OldClass oldClass, int i) { Console.WriteLine("This is Method " + i); }
internal static void Method3(this OldClass oldClass) { Console.WriteLine("This is Method 3"); }