コード例 #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();
        }
コード例 #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();
 }
コード例 #3
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();
        }
コード例 #4
0
        static void Main(string[] args)
        {
            Console.WriteLine("Funn with Extension Methods\n");
            int myInt = 12345678;

            myInt.DisplayDefiningAssembly();

            System.Data.DataSet d = new System.Data.DataSet();
            d.DisplayDefiningAssembly();

            System.Media.SoundPlayer sp = new System.Media.SoundPlayer();
            sp.DisplayDefiningAssembly();

            Console.WriteLine("Value of myInt: {0}", myInt);
            Console.WriteLine("Reversed digits pf myInt: {0}", myInt.ReverseDigits());
        }
コード例 #5
0
        public static void Main(string[] args)
        {
            int myInt = 1234567;

            myInt.DisplayDefiningAssembly();

            System.Data.DataSet d = new System.Data.DataSet();
            d.DisplayDefiningAssembly();

            System.Media.SoundPlayer player = new System.Media.SoundPlayer();
            player.DisplayDefiningAssembly();

            int rev = myInt.ReverseDigits();

            Console.WriteLine(rev);
            Console.ReadKey();
        }
コード例 #6
0
        static void InvokingExtension()
        {
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("=> Invoking Extension Methods");

            int myInt = 12345678;

            myInt.DisplayDefiningAssembly();

            System.Data.DataSet d = new System.Data.DataSet();
            d.DisplayDefiningAssembly();

            System.Media.SoundPlayer sp = new System.Media.SoundPlayer();
            sp.DisplayDefiningAssembly();

            Console.WriteLine($"Reversed digits of {myInt} is {myInt.ReverseDigits()}");
        }
コード例 #7
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Extension Methods *****\n");
            // The int has assumed a new identity!
            int myInt = 12345678;

            myInt.DisplayDefiningAssembly();
            // So has the DataSet!
            System.Data.DataSet d = new System.Data.DataSet();
            d.DisplayDefiningAssembly();
            // And the SoundPlayer!
            System.Media.SoundPlayer sp = new System.Media.SoundPlayer();
            sp.DisplayDefiningAssembly();
            Console.WriteLine("Value of myInt: {0}", myInt);
            Console.WriteLine("Reversed digits of myInt: {0}", myInt.ReverseDigits());
            Console.ReadLine();
        }
コード例 #8
0
ファイル: Program.cs プロジェクト: wordtinker/c-sharp
 static void Main(string[] args)
 {
     Console.WriteLine("***** Fun with Extension Methods *****\n");
     // The int has assumed a new identity!
     int myInt = 12345678;
     myInt.DisplayDefiningAssembly();
     // So has the DataSet!
     System.Data.DataSet d = new System.Data.DataSet();
     d.DisplayDefiningAssembly();
     // And the SoundPlayer!
     System.Media.SoundPlayer sp = new System.Media.SoundPlayer();
     sp.DisplayDefiningAssembly();
     // Use new integer functionality.
     Console.WriteLine("Value of myInt: {0}", myInt);
     Console.WriteLine("Reversed digits of myInt: {0}", myInt.ReverseDigits());
     Console.ReadLine();
 }
コード例 #9
0
ファイル: Program.cs プロジェクト: maziesmith/.NetCSharp
        static void Main(string[] args)
        {
            Console.WriteLine("**** Fun with Extension Method****");

            int myInt = 12345678;

            myInt.DisplayDefiningAssembly();

            System.Data.DataSet d = new System.Data.DataSet();
            d.DisplayDefiningAssembly();

            System.Media.SoundPlayer sp = new System.Media.SoundPlayer();
            sp.DisplayDefiningAssembly();

            Console.WriteLine($"Value of myInt: {myInt}");
            Console.WriteLine($"Reversed digits of myInt: {myInt.ReverseDigit()}");

            Console.Read();
        }
コード例 #10
0
        public static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Extension Methods *****\n");
            int myInt = 123456;

            //MyExtensions.DisplayDefiningAssembly(myInt);
            Console.WriteLine(myInt.ReverseDigits().ToString());
            myInt.DisplayDefiningAssembly();
            Console.ReadKey();

            // To же и в DataSet!
            System.Data.DataSet d = new System.Data.DataSet();
            d.DisplayDefiningAssembly();
            Console.ReadKey();

            //Ив SoundPlayer!
            System.Media.SoundPlayer sp = new System.Media.SoundPlayer();
            sp.DisplayDefiningAssembly();
            Console.ReadKey();
        }
コード例 #11
0
        private static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Extension Methods *****\n");
            const int myInt = 12345678;

            myInt.DisplayDefiningAssembly();

            var d = new System.Data.DataSet();

            d.DisplayDefiningAssembly();

            var sp = new System.Media.SoundPlayer();

            sp.DisplayDefiningAssembly();

            Console.WriteLine("Value of myInt: {0}", myInt);
            Console.WriteLine("Reversed digits of myInt: {0}", myInt.ReverseDigits());

            Console.ReadLine();
        }
コード例 #12
0
ファイル: Program.cs プロジェクト: delve/StudyingBooks
        public static void Main(string[] args)
        {
            Console.WriteLine("Fun with extensions");

            // the int has new superpowers
            int myI = 123456789;

            myI.DisplayDefiningAssembly();
            Console.WriteLine("Int only powers: I = {0}; Reversed = {1}", myI.ReverseDigits(), myI.ToString());

            // new DataSet powers...
            System.Data.DataSet d = new System.Data.DataSet();
            d.DisplayDefiningAssembly();

            // and SoubdPlayer...
            System.Media.SoundPlayer sp = new System.Media.SoundPlayer();
            sp.DisplayDefiningAssembly();

            Console.ReadLine();
        }
コード例 #13
0
        static void FuckWithExtensionMethods()
        {
            System.Console.WriteLine("=> fun with extension methods:");

            int myInt = 1234567890;

            myInt.DisplayDefiningAssembly();

            // so has the DataSet
            System.Data.DataSet d = new System.Data.DataSet();
            d.DisplayDefiningAssembly();

            // and the SoundPlayer
            System.Media.SoundPlayer sp = new System.Media.SoundPlayer();
            sp.DisplayDefiningAssembly();

            // use new integer functinoality
            System.Console.WriteLine("value of myInt: {0}", myInt);
            System.Console.WriteLine("reversed digits of myInt: {0}", myInt.ReverseDigits());

            Console.ReadLine();
        }
コード例 #14
0
ファイル: Program.cs プロジェクト: alsid12/Troelsen
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with extension methods *****\n");

            // This int has assumed a new identity!
            int myInt = 12345678;

            myInt.DisplayDefiningAssembly();

            // So has the data set!
            System.Data.DataSet d = new System.Data.DataSet();
            d.DisplayDefiningAssembly();

            // And the soundplayer!
            System.Media.SoundPlayer sp = new System.Media.SoundPlayer();
            sp.DisplayDefiningAssembly();

            // Use new integer functionality.
            Console.WriteLine("Value of myInt: {0}", myInt.ReverseDigits());

            Console.ReadLine();
        }
コード例 #15
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Extension Methods *****");

            //  本整形表示一个新的身份标识
            int myInt = 12345678;

            myInt.DisplayDefiningAssembly();

            //  下面是DataSet
            System.Data.DataSet d = new System.Data.DataSet();
            d.DisplayDefiningAssembly();

            //  下面是SoundPlayer
            System.Media.SoundPlayer sp = new System.Media.SoundPlayer();
            sp.DisplayDefiningAssembly();

            //  使用整形的新功能
            Console.WriteLine("Value of myInt: {0}", myInt);
            Console.WriteLine("Reversed digits of myInt: {0}", myInt.ReverseDigits());

            Console.ReadLine();
        }
コード例 #16
0
        /// <summary>
        /// Invoking Extension Method
        /// </summary>
        private void InvokingExtensionMethod()
        {
            Console.WriteLine("=> Invoking Extension Method: ");

            // The int has assumed a new identity
            int myInt = 12345678;

            myInt.DisplayDefiningAssembly();

            // So has the DataSet
            System.Data.DataSet d = new System.Data.DataSet();
            d.DisplayDefiningAssembly();

            // And the SoundPlayer
            System.Media.SoundPlayer sp = new System.Media.SoundPlayer();
            sp.DisplayDefiningAssembly();

            // Use new integer functionality
            Console.WriteLine("Value of mInt: {0}", myInt);
            Console.WriteLine("Reversed digits of myInt: {0}", myInt.ReverseDigits());

            Console.WriteLine();
        }
コード例 #17
0
        static void Main(string[] args)
        {
            Point ptOne = new Point(100, 100);
            Point ptTwo = new Point(40, 40);

            Console.WriteLine("ptOne = {0}", ptOne);
            Console.WriteLine("ptTwo = {0}", ptTwo);
            Console.WriteLine();
            Console.WriteLine("ptOne + ptTwo: {0} ", ptOne + ptTwo);
            Console.WriteLine("ptOne - ptTwo: {0} ", ptOne - ptTwo);
            Console.WriteLine("ptOne + ptTwo: {0} ", ptOne + ptTwo);

            // Subtract the points to make a smaller point?
            Console.WriteLine("ptOne - ptTwo: {0} ", ptOne - ptTwo);
            Console.WriteLine();

            // Prints [110, 110]
            Point biggerPoint = ptOne + 10;

            Console.WriteLine("ptOne + 10 = {0}", biggerPoint);

            // Prints [120, 120]
            Console.WriteLine("10 + biggerPoint = {0}", 10 + biggerPoint);
            Console.WriteLine();

            // Freebie +=
            Point ptThree = new Point(90, 5);

            Console.WriteLine("ptThree = {0}", ptThree);
            Console.WriteLine("ptThree += ptTwo: {0}", ptThree += ptTwo);
            Console.WriteLine();

            // Freebie -=
            Point ptFour = new Point(0, 500);

            Console.WriteLine("ptFour = {0}", ptFour);
            Console.WriteLine("ptFour -= ptThree: {0}", ptFour -= ptThree);
            Console.WriteLine();

            // Applying the ++ and -- unary operators to a Point.
            Point ptFive = new Point(1, 1);

            Console.WriteLine("++ptFive = {0}", ++ptFive);  // [2, 2]
            Console.WriteLine("--ptFive = {0}", --ptFive);  // [1, 1]
            Console.WriteLine();

            // Apply same operators as postincrement/decrement.
            Point ptSix = new Point(20, 20);

            Console.WriteLine("ptSix++ = {0}", ptSix++);  // [20, 20]
            Console.WriteLine("ptSix-- = {0}", ptSix--);  // [21, 21]
            Console.WriteLine();

            Console.WriteLine("ptOne == ptTwo : {0}", ptOne == ptTwo);
            Console.WriteLine("ptOne != ptTwo : {0}", ptOne != ptTwo);
            Console.WriteLine();

            Console.WriteLine("ptOne < ptTwo : {0}", ptOne < ptTwo);
            Console.WriteLine("ptOne > ptTwo : {0}", ptOne > ptTwo);

            Console.WriteLine("---------------------------------------------------");

            Rectangle r = new Rectangle(15, 4);

            Console.WriteLine(r.ToString());
            r.Draw();

            Console.WriteLine();

            Square s = (Square)r;

            Console.WriteLine(s.ToString());
            s.Draw();

            Console.WriteLine("---------------------------------------------------");

            Rectangle rect = new Rectangle(10, 5);

            DrawSquare((Square)rect);

            Console.WriteLine("---------------------------------------------------");

            int myInt = 12345678;

            myInt.DisplayDefiningAssembly();

            DataSet d = new DataSet();

            d.DisplayDefiningAssembly();

            System.Media.SoundPlayer sp = new System.Media.SoundPlayer();
            sp.DisplayDefiningAssembly();

            Console.WriteLine("Value of myInt: {0}", myInt);
            Console.WriteLine("Reversed digits of myInt: {0}", myInt.ReverseDigits());

            Console.WriteLine("---------------------------------------------------");

            var myCar = new { Color = "Bright Pink", Make = "Saab", CurrentSpeed = 55 };

            Console.WriteLine("My car is a {0} {1}.", myCar.Color, myCar.Make);
            BuildAnonType("BMW", "Black", 90);

            Console.WriteLine("---------------------------------------------------");

            ReflectOverAnonymousType(myCar);

            Console.ReadLine();
        }