public void AddDel(customDelegate del) { DelList.Add(del); }
static void Main(string[] args) { #region question on interview //List<customDelegate> localDelCollection = new List<customDelegate>(); //for (int i = 0; i < 15; i++) // localDelCollection.Add((msg) => Console.WriteLine(i)); //foreach (var del in localDelCollection) //{ // del(""); //} #endregion #region not working //DelEvent car = new DelEvent(); //for (int i = 0; i < 5; i++) // car.AddDel((msg) => Console.WriteLine(msg)); //car.AddDel((msg) => throw new Exception("Error!!!")); //for (int i = 0; i < 5; i++) // car.AddDel((msg) => Console.WriteLine(msg)); //car.TriggerDel(); #endregion #region not exactly //DelCollection delCollection = new DelCollection(); //for (int i = 0; i < 5; i++) // delCollection.AddDel((msg) => Console.WriteLine(msg)); //delCollection.AddDel((msg) => throw new Exception("Error!!!")); //for (int i = 0; i < 5; i++) // delCollection.AddDel((msg) => Console.WriteLine(msg)); //delCollection.TriggerDel(); //Console.WriteLine("End of delegates!"); #endregion #region the right way customDelegate dels = null; for (int i = 0; i < 5; i++) { dels += ((msg) => Console.WriteLine(msg)); } //dels += ((msg) => throw new Exception("Error!!!")); dels += Exception; for (int i = 0; i < 5; i++) { dels += ((msg) => Console.WriteLine(msg)); } dels.ExceptionSafe(new object[] { "Hello!!" }); #endregion Console.ReadLine(); }
public void AddDel(customDelegate del) { Del += del; Eve += del; }