//Pass the delegate as a parmetr to the method below
 //this delegate serves to pass back the value from the GetInteger method to the calling method in the
 //other class.
 //Recall the passed method has the same signatue and hence we can argue that the passed metthod is equivalent
 // to the delegate
 public void GetInterger(Mydelegate f)
 {
     for (int x = 1; x <= 100; x++)
     {
         f.Invoke(x);
     }
 }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Mydelegate mydelegate = new Mydelegate(Method);
            Mydelegat1 mydelegat1 = mydelegate.Invoke(new Mydelegate2(Method1), new Mydelegate3(Method2));

            mydelegat1.Invoke();
        }
Ejemplo n.º 3
0
        _Delegate()
        {
            Mydelegate mydelegate = new Mydelegate(Myclass.Method);

            mydelegate.Invoke();

            // mydelegate();
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            Mydelegate <Cat> delegateCat = new Mydelegate <Cat>(CatCreator);

            Mydelegate <Animal> delegateAnimal = delegateCat;

            Animal animal = delegateAnimal.Invoke();

            Console.WriteLine(animal.GetType().Name);
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            Mydelegate D1 = Multicast.sinus;
            Mydelegate D2 = Multicast .cosinus;

            Console.WriteLine("Simple delegate";
            D1.Invoke(70);
            D2(100);

            Console.ReadLine();

        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            Myclass myclass = new Myclass();

            Mydelegate mydelegate = null;
            //mydelegate += myclass.CallMethod1;
            //mydelegate += myclass.Calldelegate2;
            //mydelegate += myclass.Calldelegate3;
            //mydelegate();
            //mydelegate -= myclass.Calldelegate2;
            //mydelegate();
            Mydelegate newMydelegate = new Mydelegate(myclass.CallMethod1);
            Mydelegate mydelegate1   = new Mydelegate(myclass.Calldelegate2);
            Mydelegate mydelegate2   = new Mydelegate(myclass.Calldelegate3);

            mydelegate = newMydelegate + mydelegate1 + mydelegate2;

            Console.WriteLine("Enter number from 1-7");
            string chois = Console.ReadLine();

            switch (chois)
            {
            case "1":
                mydelegate.Invoke();
                break;

            case "2":
                mydelegate1.Invoke();
                break;

            case "3":
                mydelegate2.Invoke();
                break;

            case "5":
                Mydelegate Mydelegate3 = mydelegate - mydelegate1;
                Mydelegate3();
                break;
            }
        }
Ejemplo n.º 7
0
        public static void RunSynchronizedTest()
        {
            Mydelegate md;

            md  = null;
            md += new Mydelegate(() => { Console.WriteLine("1"); });
            md += new Mydelegate(() => { Console.WriteLine("2"); });
            md += new Mydelegate(() => { Console.WriteLine("4"); });
            md.Invoke();
            md = null;
            //md.Invoke();
            ClassA a  = new ClassA();
            ClassA b  = new ClassA();
            Thread t1 = new Thread(new ThreadStart(() => { a.ThearTest("1"); }));
            Thread t2 = new Thread(new ThreadStart(() => { a.ThearTest("2"); }));
            Thread t3 = new Thread(new ThreadStart(() => { b.ThearTest("3"); }));
            Thread t4 = new Thread(new ThreadStart(() => { b.ThearTest("4"); }));

            t1.Start();
            t2.Start();
            t3.Start();
            t4.Start();
            Console.WriteLine("Stort");
        }
Ejemplo n.º 8
0
        public EventsAndDelegatesv3()
        {
            Mydelegate mydelegate, mydelegate2, mydelegate3, mydelegate4;

            mydelegate  = new Mydelegate(Method1);
            mydelegate2 = new Mydelegate(Method2);

            mydelegate3 = mydelegate + mydelegate2;
            mydelegate4 = mydelegate - mydelegate2;

            mydelegate.Invoke("AAA");
            mydelegate2("BBB");
            mydelegate3("CCC");

            mydelegate4("DDD");

            mydelegate4 = mydelegate3 - mydelegate;
            mydelegate4("EEE");

            mydelegate4 = mydelegate3 - mydelegate2;
            mydelegate4("FFF");

            Console.ReadLine();
        }
Ejemplo n.º 9
0
 private void btnMultiply_Click(object sender, RoutedEventArgs e)
 {
     LResult.Content = multiplyEvent.Invoke(TBFirst.Text, TBLast.Text);
 }
Ejemplo n.º 10
0
 private void btnDivide_Click(object sender, RoutedEventArgs e)
 {
     LResult.Content = divideEvent.Invoke(TBFirst.Text, TBLast.Text);
 }
Ejemplo n.º 11
0
 private void btnPlus_Click(object sender, RoutedEventArgs e)
 {
     LResult.Content = plusEvent.Invoke(TBFirst.Text, TBLast.Text);
 }
Ejemplo n.º 12
0
        public static void Main(string[] args)
        {
            var    users         = new List <CuentaBancaria>();
            int    opc1          = 0;
            string numTitular    = "";
            double BalanceCuenta = 0;

            do
            {
                Console.WriteLine(menu1());
                Console.WriteLine("Digite la opcion deseada: ");
                opc1 = Int32.Parse(Console.ReadLine());
                switch (opc1)
                {
                case 1:
                    Console.WriteLine("Ingrese una nueva cuenta bancaria.....");
                    Console.WriteLine("ingrese nombre del titular de la cuenta:  ");
                    numTitular = Console.ReadLine();
                    Console.WriteLine("Digite el saldo a ingresar en la cuenta: ");
                    BalanceCuenta = Int32.Parse(Console.ReadLine());

                    users.Add(new CuentaBancaria(numTitular, BalanceCuenta));


                    break;

                case 2:
                    Accountmanagment = showAccounts;
                    Accountmanagment.Invoke(users);

                    break;

                case 3:
                    //Delegate Explicito
                    Accountmanagment  = showAccounts;
                    Accountmanagment += showSalary;

                    Accountmanagment.Invoke(users);
                    break;

                case 4:
                    //Action

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

                    Action <List <CuentaBancaria> > MyAccountAction = (maa) =>
                    {
                        maa.ForEach(account =>
                        {
                            Console.WriteLine($"Nombre: {account._name}, Saldo: ${account._ActualBalance}");
                        });
                    };

                    MyAccountAction += maas =>
                    {
                        double salary = 0;

                        maas.ForEach(account =>
                        {
                            salary += account._ActualBalance;
                        });

                        Console.WriteLine($"Suma de salarios: ${salary}");
                    };
                    MyAccountAction.Invoke(users);

                    MyAccountAction = voc =>
                    {
                        voc.ForEach(titular =>
                        {
                            if (titular._name[0].Equals('a') || titular._name[0].Equals('e') ||
                                titular._name[0].Equals('i') || titular._name[0].Equals('o') ||
                                titular._name[0].Equals('u'))
                            {
                                Console.WriteLine("\n inicia con vocal..");
                                Console.WriteLine($"Nombre: {titular._name}, Saldo: ${titular._ActualBalance}");
                            }
                            else
                            {
                                Console.WriteLine(" ");
                            }
                        });
                    };
                    MyAccountAction.Invoke(users);

                    break;

                case 5:
                    Console.WriteLine("Saliendo del menu.....");
                    break;
                }
            } while (opc1 != 5);
        }