Exemplo n.º 1
0
        public Delegate()
        {
            ReturnInt d1 = new ReturnInt(ReturnIntMethod);

            Console.WriteLine(d1.Invoke(10));

            SetInteger = SetIntegerMethod;
            SetInteger.Invoke(1);

            GetInteger = GetIntegerMethod;
            Console.WriteLine(GetInteger.Invoke(2));

            ConvertorPointer = ConvertIntToStringMethod;
            Console.WriteLine(ConvertorPointer.Invoke(3));

            ComparisonPointer = new Comparison <int>(CompareIntMethod);
            int[] arr = new int[] { 1, 23, 5 };
            Array.Sort(arr, ComparisonPointer);

            Console.WriteLine("{0}", string.Join(", ", arr));
            //arr.ToList().ForEach(Console.WriteLine);

            MyEvent += new EventHandler(DoNothing);
            MyEvent -= null;
        }
Exemplo n.º 2
0
        public static int InlineDelegate2()
        {
            here = delegate { return(124); };

            var i = here();

            return(i);
        }
Exemplo n.º 3
0
        public static int InlineDelegate1()
        {
            ReturnInt o = delegate { return(124); };

            var i = o();

            return(i);
        }