コード例 #1
0
ファイル: ClassCounter.cs プロジェクト: stasiko/console
        public event MethodContainer OnCount = () => { }; //Создание анонимной функции на основе лямбда выражения.




        //public event MethodContainer OnCount = delegate{};
        //public event Action OnCount = delegate{};
        //public event EventHandler MyEvent = delegate { };


        public void Count()
        {

            var test = OnCount.GetInvocationList();

            Handler_Two handlerThree = new Handler_Two();


            OnCount += handlerThree.Message;

            //4
            var count1 = OnCount;
            //count1();


            //var test2 = OnCount.    .GetInvocationList();

            OnCount -= handlerThree.Message;

            //var count2 = (MethodContainer)OnCount;

            //var count3 = OnCount;

            var count2 = OnCount;

            //OnCount += handlerThree.Message;

            //OnCount.GetInvocationList();
            //count3.GetInvocationList();
            //count2.GetInvocationList();



            for (int i = 0; i < 100; i++)
            {
                if (i == 71)
                {
                    OnCount.Invoke();
                }
            }


            Action a = () => Console.WriteLine("event 1");
            var b = a;
            a += () => Console.WriteLine("event 2");

            Console.WriteLine("EVENT a:");
            Console.WriteLine("---------------");
            a();
            Console.WriteLine();
            Console.WriteLine("EVENT b:");
            Console.WriteLine("---------------");
            b();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: stasiko/console
        public static void EventExpample(string[] args)
        {
            ClassCounter counter = new ClassCounter();
            Handler_One handlerOne = new Handler_One();
            Handler_Two handlerTwo = new Handler_Two();

            counter.OnCount += handlerOne.Message;
            counter.OnCount += handlerTwo.Message;



            counter.Count();

        }