Esempio n. 1
0
        //public static void Addnum(int a, int b)
        //{
        //    Console.WriteLine(a + b);
        //}
        static void Main(string[] args)
        {
            // AddnumDelegate obj = new AddnumDelegate(Addnum);
            AddnumDelegate obj1 = delegate(int a, int b)
            {
                Console.WriteLine(a + b);
            };
            // obj.Invoke("Girls");
            // Console.WriteLine(obj.Invoke("Girls"));
            mulDelegate obj = delegate(int a, int b)
            {
                Console.WriteLine(a * b);
            };
            divDelegate obj2 = delegate(int a, int b)
            {
                Console.WriteLine(a / b);
            };
            HelloDelegate obj3 = delegate(string name)
            {
                Console.WriteLine("The name is: " + name);
            };

            obj1.Invoke(10, 20);
            obj.Invoke(15, 30);
            obj2.Invoke(30, 15);
            obj3.Invoke("kavya");
            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            HelloDelegate hd = delegate(string greet)
            {
                Console.WriteLine(greet);
            };

            hd.Invoke("Good Morning!!");
            AddDelegate ad = delegate(double val1, double val2)
            {
                Console.WriteLine(val1 + val2);
            };

            ad.Invoke(123.3446, 2343.44466);
            subDelegate sd = delegate(double val1, double val2)
            {
                Console.WriteLine(val1 - val2);
            };

            sd.Invoke(365.35356, 123.43454);
            MultiplyDelegate md = delegate(int val1, int val2)
            {
                Console.WriteLine(val1 * val2);
            };

            sd.Invoke(125, 132);
            Console.ReadKey();
        }
Esempio n. 3
0
    static void Main(string[] args)
    {
        HelloDelegate hello1 = new HelloDelegate(SayHello);
        HelloDelegate hello2 = SayHello;

        hello1.Invoke();
        hello2.Invoke();
        hello1();
    }
Esempio n. 4
0
        static void Main(string[] args)
        {
            SomeClass someClass = new SomeClass();

            HelloDelegate hD = new HelloDelegate(someClass.SayHello);

            Console.WriteLine(hD.Invoke("Вася"));

            Console.WriteLine(hD("Вася"));

            Console.ReadKey();
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            HelloDelegate obj = delegate(string val)
            {
                return("Hello " + val + "!");
            };

            string str = obj.Invoke("Mubashir");

            Console.WriteLine(str);

            Console.ReadLine();
        }
Esempio n. 6
0
        static void Main(string[] args)
        {
            Program     p = new Program();
            AddDelegate a = new AddDelegate(p.Add);

            a.Invoke(10, 10);

            HelloDelegate h   = new HelloDelegate(Hello);
            string        str = h.Invoke("swamy");

            Console.WriteLine(str);
            Console.ReadLine();
        }
Esempio n. 7
0
    static void Main(string[] args)
    {
        HelloDelegate hello1 = new HelloDelegate(SayHello);
        HelloDelegate hello2 = SayHello;

        hello1.Invoke();
        hello2.Invoke();
        hello1();
        Test(hello1);

        hello1 += SayHello;

        Sample        sam    = new Sample();
        HelloDelegate hello3 = sam.SayHello;

        sam();
    }
Esempio n. 8
0
        static void Main(string[] args)
        {
            MyClass myClass = new MyClass();

            // 指定委派物件到一個執行個體上的方法(函式簽章需要相同)
            HelloDelegate helloDelegate = myClass.SayHelloInstance;

            // 直接執行該委派物件上指定的物件方法,
            // 也就是呼叫 MyClass.SayHelloInstance
            helloDelegate("Vulcan");
            // 使用委派的 Invoke 方法來同步呼叫此方法
            helloDelegate.Invoke("Vulcan");

            // 指定委派物件到一個靜態方法(函式簽章需要相同)
            helloDelegate = new HelloDelegate(MyClass.SayHelloStatic);
            // 直接執行該委派物件上指定的靜態方法,
            // 也就是呼叫 MyClass.SayHelloStatic
            helloDelegate("Ada");
            // 使用委派的 Invoke 方法來同步呼叫此方法
            helloDelegate.Invoke("Ada");

            Console.WriteLine("Press any key for continuing...");
            Console.ReadKey();
        }