Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Func<T>");

            Method(1);

            MyDelegateInt myDelegate = Method;

            myDelegate(2);

            myDelegate += Method;
            myDelegate += Method;
            myDelegate += Method;

            int result = myDelegate(4); //result == 4*8?

            #region result
            //result == 8 :)
            #endregion

            Func <int>      func1 = MethodWithoutParams;
            Func <int, int> func2 = Method;
            #region Func<T>
            //Func<T>               - no params, returns T
            //Func<X, T>            - X as param, returns T
            //Func<X,Y, T>          - X, Y as params, returns T
            //.....
            //Func<X,Y,Z,A,B, T>    - X,Y,Z,A,B as params, returns T
            #endregion

            Console.ReadLine();
        }
Exemplo n.º 2
0
    {//ExorTek(Mehmet Demirel)
        static void Main(string[] args)
        {
            CustomerManager customerManager = new CustomerManager();
            //customerManager.SendMessage();
            //customerManager.ShowAlert();

            MyDelegate myDelegate = customerManager.SendMessage;

            myDelegate += customerManager.ShowAlert;
            //myDelegate -= customerManager.SendMessage;
            myDelegate();

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

            MyDelegateTwo myDelegateTwo = customerManager.SendMessageTwo;

            myDelegateTwo += customerManager.ShowAlertTwo;
            myDelegateTwo("Hello");

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

            MathClass     mathClass     = new MathClass();
            MyDelegateInt myDelegateInt = mathClass.Sum;
            // myDelegateInt += mathClass.Multiplication;
            var sum = myDelegateInt(5, 4);

            Console.WriteLine(sum);

            Console.ReadLine();
        }
Exemplo n.º 3
0
        private void BtnClick_Click(object sender, EventArgs e)
        {
            P = new ListBoxPrint(LbxOutput);
            MyDelegateInt delOne = this.MyFirstMethod;
            MyDelegateInt delTwo = this.MySecondMethod;

            int a = 5; delOne.Invoke(a);
            int b = 9; delTwo.Invoke(b);
            int x = 8; AnotherMethod(x, delOne);
            int y = 16; AnotherMethod(y, delTwo);
        }
Exemplo n.º 4
0
 private void AnotherMethod(int x, MyDelegateInt y)
 {
     P.Print($"AnotherMethod = {x}");
     y.Invoke(x);          //  y.DynamicInvoke(x);
 }
Exemplo n.º 5
0
        public static void Show(MyDelegateInt mdl)
        {
            int result = mdl(10, 20, 30);

            Console.WriteLine(result);
        }