static void Main(string[] args) { Console.WriteLine("Delegate Lab 03"); President first = new President { FirstName = "George", LastName = "Washington", State = "Virginia", Party = "independent", Year = 1788 }; Console.WriteLine("========= three different ways ========="); first.PrintFirstName(first); Console.WriteLine(first.GetFirstName()); Console.WriteLine(first.FirstName); Console.WriteLine(first.FirstName.GetType()); Console.WriteLine("=========non delegate demostration ========="); Console.WriteLine(first.FirstName); Console.WriteLine(first.LastName); Console.WriteLine(first.State); Console.WriteLine(first.Party); Console.WriteLine(first.Year); Console.WriteLine(first.ToString()); 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()); myFirstDel = first.ToString; 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); mySecondDel = new PrintPresDel(first.PrintString); mySecondDel(first); Console.WriteLine("=========third delegate demostration ========="); PrintPresDel myThirdDel = new PrintPresDel(first.PrintFirstName); myThirdDel += new PrintPresDel(first.PrintLastName); myThirdDel += new PrintPresDel(first.PrintState); myThirdDel += new PrintPresDel(first.PrintParty); myThirdDel += new PrintPresDel(first.PrintYear); myThirdDel += new PrintPresDel(first.PrintString); myThirdDel(first); }
public void PrintString(President p) => Console.WriteLine($"{FirstName} {LastName} from {State} was a {Party} elected in {Year}.");
public void PrintYear(President p) => Console.WriteLine(p.Year.ToString());
public void PrintParty(President p) => Console.WriteLine(p.Party);
public void PrintState(President p) => Console.WriteLine(p.State);
public void PrintLastName(President p) => Console.WriteLine(p.LastName);