示例#1
0
        static void Main(string[] args)
        {
            Mydel del1 = new Mydel(add);
            Mydel del2 = new Mydel(sub);


            Console.WriteLine(del1(12, 12));
            Console.WriteLine(del2(10, 5));

            Mydel1 dl = new Mydel1(area);

            Console.WriteLine(dl(3));

            Console.ReadKey();
        }
示例#2
0
        static void Main(string[] args)
        {
            Console.BackgroundColor = ConsoleColor.White;
            Console.ForegroundColor = ConsoleColor.Red;
            class1 c1 = new class1();
            Mydel1 m1 = new Mydel1(c1.sum);

            m1 += new Mydel1(c1.sub);
            m1 += new Mydel1(c1.Mul);
            m1 += new Mydel1(c1.Div);
            if (m1 != null)
            {
                m1(10, 2);
            }
            Console.ReadLine();
        }
示例#3
0
        static void Main(string[] args)
        {
            Console.WriteLine("***Quiz on Delegate***");
            int a = 25, b = 37, c = 100;
            A   obA1 = new A();
            A   obA2 = new A();

            Mydel1 del1 = obA1.Sum;//Pointing Sum(int a, int b)

            Console.WriteLine("del1 is pointing Sum(int a,int b):");
            Console.WriteLine("Sum of a and b is: {0}", del1(a, b));

            Mydel2 del2 = obA1.Sum;//pointing Sum(int a, int b, int c)

            Console.WriteLine("del2 is pointing Sum(int a,int b,int c):");
            Console.WriteLine("Sum of a, b and c is: {0}", del2(a, b, c));
            //same as
            //Console.WriteLine("Sum of a, b and c is: {0}", del2.Invoke(a, b, c));
            Console.ReadKey();
        }
示例#4
0
 public void display()
 {
     Click += new Mydel1(Click_Method);
     Click();
 }