Exemplo n.º 1
0
            public static void RunLab3()
            {
                Console.WriteLine("Hello Delegates!");
                President first = new President
                {
                    FirstName = "George",
                    LastName  = "Washington",
                    State     = "Virginia",
                    Party     = "none",
                    Year      = 1788
                };

                Console.WriteLine("=========non delegate demostration =========");
                Console.WriteLine(first.ToString());
                first.PrintFirstName(first);
                Console.WriteLine(first.GetFirstName());
                Console.WriteLine(first.FirstName);
                Console.WriteLine(first.FirstName.GetType());

                Console.WriteLine("=========first delegate demostration =========");
                GetPresDel myFirstDel = new GetPresDel(first.GetFirstName);

                Console.WriteLine(myFirstDel());
                myFirstDel = first.GetLastName;
                Console.WriteLine(myFirstDel());
                myFirstDel = first.GetState;
                Console.WriteLine(myFirstDel());
                myFirstDel = first.GetParty;
                Console.WriteLine(myFirstDel());
                myFirstDel = first.GetYear;
                Console.WriteLine(myFirstDel());

                Console.WriteLine("=========second delegate demostration =========");
                PrintPresDel mySecondDel = new PrintPresDel(first.PrintFirstName);

                mySecondDel(first);
                mySecondDel = new PrintPresDel(first.PrintLastName);
                mySecondDel(first);
                mySecondDel = new PrintPresDel(first.PrintState);
                mySecondDel(first);
                mySecondDel = new PrintPresDel(first.PrintParty);
                mySecondDel(first);
                mySecondDel = new PrintPresDel(first.PrintYear);
                mySecondDel(first);
            }