예제 #1
0
    static void Main()
    {
        MyEvent  evt   = new MyEvent();
        UserInfo user1 = new UserInfo(Name: "Alex", Family: "Erohin", Age: 26);

        // Добавляем обработчик события
        evt.UserEvent += user1.UserInfoHandler;

        // Добавляем обработчик события
        evt.UserEvent += user1.UserInfoHandler;

        // Запустим событие
        evt.OnUserEvent();

        Console.ReadLine();
    }
예제 #2
0
        static void Main(string[] args)
        {
            List <string> family_list = new List <string>();

            Father   father   = new Father();
            Mother   mother   = new Mother();
            Daughter daughter = new Daughter();


            father.gender = "male";
            father.name   = "Alex";
            father.Age    = 40;
            family_list.Add(father.name);
            Console.WriteLine(family_list[0]);
            Console.WriteLine();
            father.Work();
            MyEvent evt1 = new MyEvent();

            evt1.UserEvent += father.FamilyInfoHandler;
            evt1.OnUserEvent();

            mother.gender = "female";
            mother.name   = "Anna";
            mother.Age    = 36;
            family_list.Add(mother.name);
            Console.WriteLine(family_list[1]);
            Console.WriteLine();
            mother.Work();
            MyEvent evt2 = new MyEvent();

            evt2.UserEvent += mother.FamilyInfoHandler;
            evt2.OnUserEvent();


            daughter.gender = "female";
            daughter.name   = "Alice";
            daughter.Age    = 4;
            family_list.Add(daughter.name);
            Console.WriteLine(family_list[2]);
            Console.WriteLine();
            MyEvent evt3 = new MyEvent();

            evt3.UserEvent += daughter.FamilyInfoHandler;
            evt3.OnUserEvent();
        }