Exemplo n.º 1
0
        public static void Main()
        {
            SomeDelagete dlg = new SomeDelagete(SomeMethod);
            // dlg(10);

            // does not compile because of string parameter
            // dlg = new SomeDelagete(AnotherMethod);

            // dlg = new SomeDelagete(Console.WriteLine);
            var textDlg = new SomeStringParamDelegate(Console.WriteLine);

            // dlg(100);
            // textDlg("1000");

            ConvertStrings cnvrtDlg = new ConvertStrings(int.Parse);

            int someNumber = cnvrtDlg("100");

            // Console.WriteLine(someNumber);

            dlg = Console.WriteLine;

            MulticastDelegate multiFunctions = Sum;

            multiFunctions += Product;
            multiFunctions += Remainder;

            for (int i = 0; i < 50; i++)
            {
                multiFunctions += Sum;
                multiFunctions += Product;
                multiFunctions += Remainder;
            }

            multiFunctions -= Remainder;

            // int result = multiFunctions(10, 6);
            // Console.WriteLine("Delagete result: " + result);

            SomeStringParamDelegate annDlg = delegate(string text)
            {
                Console.WriteLine("Zdrasti " + text);
            };

            annDlg("Ivaylo!");
        }
Exemplo n.º 2
0
        public static void Main()
        {
            SomeDelagete dlg = new SomeDelagete(SomeMethod);
            // dlg(10);

            // does not compile because of string parameter
            // dlg = new SomeDelagete(AnotherMethod);

            // dlg = new SomeDelagete(Console.WriteLine);
            var textDlg = new SomeStringParamDelegate(Console.WriteLine);

            // dlg(100);
            // textDlg("1000");

            ConvertStrings cnvrtDlg = new ConvertStrings(int.Parse);

            int someNumber = cnvrtDlg("100");
            // Console.WriteLine(someNumber);

            dlg = Console.WriteLine;

            MulticastDelegate multiFunctions = Sum;
            multiFunctions += Product;
            multiFunctions += Remainder;

            for (int i = 0; i < 50; i++)
            {
                multiFunctions += Sum;
                multiFunctions += Product;
                multiFunctions += Remainder;
            }

            multiFunctions -= Remainder;

            // int result = multiFunctions(10, 6);
            // Console.WriteLine("Delagete result: " + result);

            SomeStringParamDelegate annDlg = delegate(string text)
            {
                Console.WriteLine("Zdrasti " + text);
            };

            annDlg("Ivaylo!");
        }