public static void Main7() { CheckLengthOfString d = LessThanFive; d += MoreThanFive; d += ExactlyFive; //List<bool> results = new List<bool>(); //foreach (var del in d.GetInvocationList()) //{ // results.Add((bool)del.DynamicInvoke("Message")); // Console.WriteLine(string.Join(", ", results)); //} // List<bool> results = d.GetInvocationList().Select(del => (bool)del.DynamicInvoke("Message")).ToList(); GetLengths g = x => x.Length; g += x => x.Length + 2; g += x => x.Length + 1; List <bool> results = GottaCatchEmAll <bool>(d, "Message"); List <int> lengths = GottaCatchEmAll <int>(g, "Message"); Console.WriteLine(string.Join(", ", results)); Console.WriteLine(string.Join(", ", lengths)); Console.ReadKey(); }
public static void Test() { #region Lecture1 Printer p = Print; p += Print; p += PrintTwice; p += Print; p += PrintTwice; p += Print; p -= Print; p("Message"); Delegate[] delegates = p.GetInvocationList(); foreach (var del in delegates) { //Console.WriteLine(del.Method); } #endregion Lecture1 #region Lecture2 CheckLengthOfString d = LessThanFive; d += MoreThanFive; d += ExactlyFive; /* Hard Way * List<bool> results = new List<bool>(); * * foreach(var del in d.GetInvocationList()) * { * results.Add((bool)del.DynamicInvoke("Message")); * } */ /* Static Way * List<bool> results = d.GetInvocationList().Select(del => (bool)del.DynamicInvoke("Message")).ToList(); */ /* Generic Way */ List <bool> results = GottaCatchEmAll <bool>(d, "Message"); Console.WriteLine(string.Join(", ", results)); GetLengths g = x => x.Length; g += x => x.Length + 1; g += x => x.Length + 2; List <int> lengths = GottaCatchEmAll <int>(g, "Message"); Console.WriteLine(string.Join(", ", g)); Console.WriteLine(d("Message")); #endregion Lecture2 #region Lecture 3 Action <string> printer = Print; printer += PrintTwice; printer("Message"); #endregion Lecture 3 }