Ejemplo n.º 1
0
 public void AddDel(customDelegate del)
 {
     DelList.Add(del);
 }
Ejemplo n.º 2
0
        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();
        }
Ejemplo n.º 3
0
 public void AddDel(customDelegate del)
 {
     Del += del;
     Eve += del;
 }