Esempio n. 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Extension Methods *****\n");

            #region Display defining assembly extension
            // The int has assumed a new identity!
            int myInt = 12345678;
            myInt.DisplayDefiningAssembly();

            // So does this DataSet!
            System.Data.DataSet d = new System.Data.DataSet();
            d.DisplayDefiningAssembly();

            // And this MediaPlayer!
            System.Media.SoundPlayer sp = new System.Media.SoundPlayer();
            sp.DisplayDefiningAssembly();

            // Remember!  Extension methods can be called as normal static
            // methods.
            MyExtensions.DisplayDefiningAssembly(false);
            #endregion

            #region New integer functionality
            // Use new integer functionality.
            Console.WriteLine("Value of myInt: {0}", myInt);
            Console.WriteLine("Reversed digits of myInt: {0}", myInt.ReverseDigits());
            myInt.Foo();
            myInt.Foo("Ints that Foo?  Who would have thought it!");
            #endregion

            UseCar();
            Console.ReadLine();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            int myint = 12345678;

            myint.DisplayDefiningAssembly(); //notice the method can be used directly , this is the case with all the static methods.
            System.Media.SoundPlayer sp = new System.Media.SoundPlayer();
            sp.DisplayDefiningAssembly();
            MyExtensions.DisplayDefiningAssembly(123);
            int a = MyExtensions.ReverseDigits(123);

            Console.WriteLine(a);
            Console.ReadKey();
        }