Exemple #1
0
        static void Main()
        {
            // Call the two overloaded versions of the Display method.
            // The first call passes in the int value of 42.
            // The second call passes in the string value of "Hello Overloading".
            Overloading.Display(42);
            Overloading.Display("Hello Overloading");


            // Access the indexer property on the IndexerProperty class,
            // specifying the index value of 42, and display the result
            // in the console output.
            IndexerProperty ip = new IndexerProperty();

            Console.WriteLine(ip["42"]);

            // Declare two int variables named x and y with the initial
            // values of 3 and 4. Then display the two values on the console.
            // Then call the GenericSwapMethod, passing in the two parameters.
            // After that, display the values on the console output and see
            // that they are swapped.
            int x = 3;
            int y = 4;

            Console.WriteLine($"x: {x}, y: {y}");
            Generics.GenericSwapMethod <int>(ref x, ref y);
            Console.WriteLine($"x: {x}, y: {y}");
            System.Console.WriteLine(x + " " + y);

            // Declare an array of int named numbers and initialize
            // it with the element values: 1, 2, 3, 4, 5, 6, 7, 8.
            // Then call the DisplayEvens method and see that only even
            // elements are displayed.
            int[] numbers = { 1, 2, 3, 4, 5, 6, 7, 8 };
            Linq.DisplayEvens(numbers);


            // Call the AddIntegersFromOneUpTo method with a parameter set to 100.
            // Then display the result on the console output.
            int gaussResult = Gauss.AddIntegersFromOneUpTo(100);

            Console.WriteLine(gaussResult);
        }