Beispiel #1
0
        static void Main(string[] args)
        {
            Del del = new Del(M1);
            del += MM;

            // del += M2;

            DelInt delint = new DelInt(M2);
            Console.WriteLine(delint(40));
            del();
            Console.WriteLine("del-M1");
            del -= M1;
            del();

            Console.Read();
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            Del del = new Del(M1);

            del += MM;

            // del += M2;


            DelInt delint = new DelInt(M2);

            Console.WriteLine(delint(40));
            del();
            Console.WriteLine("del-M1");
            del -= M1;
            del();

            Console.Read();
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            Console.WriteLine(
                "Integer: " + 10 +
                " Double: " + 3.14 +
                " Boolean: " + true);
            string fooString = "\"escape\" quotes and add \n (new lines) and \t (tabs)";

            Console.WriteLine(fooString);

            char     charFromString = fooString[2];
            string   fooFs          = string.Format("Check Check, {0} {1}, {0} {1:0.0}", 1, 2);
            DateTime fooDate        = DateTime.Now;

            Console.WriteLine(fooDate.ToString("hh:mm, dd MMM yyyy"));
            string    bazString        = @"Here's some stuff
on a new line! ""Wow!"", the masses 
cried";
            const int HoursWorkPerWeek = 9001;

            Console.WriteLine("\n->Operators");
            int i1 = 1, i2 = 2; // Shorthand for multiple declarations

            // Arithmetic is straightforward
            Console.WriteLine(i1 + i2 - i1 * 3 / 7); // => 3


            //Change Git
            //Change 2

            string s = "Hello Extension Methods";
            int    i = s.WordCount();

            A a = new A();
            B b = new B();
            C c = new C();

            a.MethodA(1);         // Extension.MethodA(object, int)
            a.MethodA("hello");   // Extension.MethodA(object, string)

            a.MethodB();          // A.MethodB()

            b.MethodA(1);         // B.MethodA(int)
            b.MethodB();          // B.MethodB()

            b.MethodA("hello");   // Extension.MethodA(object, string)

            c.MethodA(1);         // C.MethodA(object)
            c.MethodA("hello");   // C.MethodA(object)
            c.MethodB();          // C.MethodB()

            int?nullable = null;  // short hand for Nullable<int>

            Console.WriteLine("Nullable variable: " + nullable);

            // Instantiate the delegate.
            Del handler = DelegateMethod;

            // Call the delegate.
            handler("Hello World");
            MethodWithCallback(1, 2, handler);

            MethodClass obj = new MethodClass();

            Del d0 = obj.Method1;

            d0 += obj.Method2;
            d0 += DelegateMethod;

            Del d1 = obj.Method1;
            Del d2 = obj.Method2;
            Del d3 = DelegateMethod;

            Del allMethodsDelegate = d1 + d2;

            allMethodsDelegate += d3;

            allMethodsDelegate -= d1;
            Del oneMethodDelegate = allMethodsDelegate - d2;

            //An anonymous method
            DelAn d = delegate(int k) { Console.WriteLine("The number is " + k); };

            d(5);

            //Expression lambda
            DelInt myDelegate = x => x * x;
            int    j          = myDelegate(5); //j = 25

            //Statement lambda
            Del testDel = n => {
                string st = n + " World";
                Console.WriteLine(st);
            };

            testDel("Hello");


            Func <int, bool> myFunc = x => x == 5;
            bool             result = myFunc(4);

            int[] numbers    = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };
            int   oddNumbers = numbers.Count(n => n % 2 == 1);

            Console.WriteLine(oddNumbers);
            Console.ReadLine();
        }