Exemplo n.º 1
0
        static void Main()
        {
            DemoDelegate d1 = One;

            d1 += Two;

            Delegate[] delegates = d1.GetInvocationList();
            foreach (DemoDelegate d in delegates)
            {
                try
                {
                    d();
                }
                catch (Exception)
                {
                    Console.WriteLine("Exception caught");
                }
            }

            //try
            //{
            //   d1();
            //}
            //catch (Exception)
            //{
            //   Console.WriteLine("Exception caught");
            //}
        }
        static void Main(string[] args)
        {
            DemoDelegate one = Demo.One;

            CallDelegate(() => one);

            // show used variable names
            foreach (var item in varNamesUsed)
            {
                Console.WriteLine(item);
            }
            Console.ReadKey();
        }
Exemplo n.º 3
0
        public static void Main(string[] args)
        {
            /*DemoDelegate.ShowMsg("Hello world! ");
             * DemoDelegate dmo = new DemoDelegate();
             * dmo.ShowInfo("Show me what you got");*/
            DemoDelegate dmos = new DemoDelegate();

            ss += new DemoDelegate().ShowInfo;
            ss += DemoDelegate.ShowMsg;
            ss += DemoDelegate.ShowMsg;
            ss("Xin chao cac ban"); // chay delegate

            DemoDelegate dd = new DemoDelegate();

            dd.Running();
        }
Exemplo n.º 4
0
        private static void DelegatesAndAnonymousMethods()
        {
            var demoDelegate   = new DemoDelegate();
            var simpleDelegate = new SimpleDelegate(demoDelegate.MethodA);
            ReturnValueDelegate   returnValueDelegate   = demoDelegate.MethodB;
            TwoParametersDelegate twoParametersDelegate = demoDelegate.MethodC;

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

            simpleDelegate();
            returnValueDelegate();
            twoParametersDelegate("Michael", 43);

            demoDelegate.Repeat3Times(simpleDelegate);
            demoDelegate.Repeat3Times2(delegate(string n, int a) { Console.WriteLine("delegate({0}, {1})", n, a); });

            Console.WriteLine();
        }
Exemplo n.º 5
0
        public void Exevute()
        {
            DemoDelegate del = Method1;

            del("Test");

            del = Method2;
            del("Method2");

            var x = DeleDemo(delegate
            {
                return(100);
            });

            var s = DeleDemo(delegate
            {
                return(200);
            });

            MyClass lib = new MyClass();
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            DemoDelegate delegateHello = new DemoDelegate(MethodHello);
            DemoDelegate delegateHi = new DemoDelegate(MethodHi);
            delegateHello();
            delegateHi();
            Console.WriteLine("--------------------");

            DemoDelegate multiDelegate = new DemoDelegate(MethodHello);
            multiDelegate += MethodHi;
            multiDelegate();
            Console.WriteLine("--------------------");

            multiDelegate -= MethodHi;
            multiDelegate();
            Console.WriteLine("--------------------");

            multiDelegate = MethodHi;
            multiDelegate();

            Console.ReadKey();
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            DemoDelegate delegateHello = new DemoDelegate(MethodHello);
            DemoDelegate delegateHi    = new DemoDelegate(MethodHi);

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

            DemoDelegate multiDelegate = new DemoDelegate(MethodHello);

            multiDelegate += MethodHi;
            multiDelegate();
            Console.WriteLine("--------------------");

            multiDelegate -= MethodHi;
            multiDelegate();
            Console.WriteLine("--------------------");

            multiDelegate = MethodHi;
            multiDelegate();

            Console.ReadKey();
        }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            int x = 1;
            PassingParamters pp = new PassingParamters();

            pp.ChangeVal(ref x);

            int y;

            pp.GetVal(out y);

            long l4 = 3;
            int  i4 = (int)l4;

            EventDemo  evd    = new EventDemo();
            Subscriber subscr = new Subscriber();

            evd.FireEvent();
            evd.DemoEvent += subscr.Handler;
            evd.FireEvent();

            Demo f = new Demo();
            // BarDelegate d1 = new BarDelegate(f.Bar);
            DemoDelegate d1 = f.Bar;

            d1(33);

            DemoDelegate d2 = Demo.Foo;
            DemoDelegate d3 = d1 + d2;

            int i = 0;

            while (i < 3)
            {
                Console.WriteLine(i++);
            }

            i = 0;
            do
            {
                Console.WriteLine(i++);
            } while (i < 3);

            int[] arr1 = { 1, 2, 3 };
            foreach (int i1 in arr1)
            {
                Console.WriteLine(i1);
            }

            short  s  = 2;
            long   l  = 3;
            uint   i2 = 4;
            ushort s2 = 5;
            ulong  l2 = 6;

            Console.WriteLine("{0} {1} {2} {3} {4} {5}",
                              i, s, l, i2, s2, l2);

            SomeData d = Singleton.GetObject();

            int[] arr = new int[3] {
                1, 2, 3
            };
            int[] arr2 = { 1, 2, 3 };

            Color c = Color.Red;

            string col = GetColor(Suit.Diamond);
        }
Exemplo n.º 9
0
        static void Main(string[] args)
        {
            DemoDelegate one = Demo.One;

            CallDelegate(() => one);
        }
Exemplo n.º 10
0
 static void CallBack(DemoDelegate demoDelegate)
 {
     demoDelegate();
 }