Exemple #1
0
        static void Main()
        {
            Student student = new Student("3200707001", "闭敏媛")
            {
                PhoneNumber = "15699996666"
            };
            BookOrderManager bookOrderManager = new BookOrderManager();

            student.SelectCourseEvent += bookOrderManager.AddBookOrder;                              //为事件注册处理函数;事件不能通过=赋值,必须通过+=注册(订阅);
            student.SelectCourseEvent += SmsService.InformAfterSelectCourse;
            student.ShowMenu();
            Read();
        }
Exemple #2
0
        static void Main()
        {
            Student student = new Student("3200707001", "闭敏媛")
            {
                PhoneNumber = "17877778888"
            };
            BookOrderManager bookOrderManager = new BookOrderManager();

            student.AfterSelectCourse  = bookOrderManager.AddBookOrder;                             //委托引用指定的函数;
            student.AfterSelectCourse += SmsService.InformAfterSelectCourse;                        //委托重载了运算符,从而引用更多函数,实现多播委托;
            student.ShowMenu();

            /*
             * student.AfterSelectCourse(student, "JAVA");                                 //公有委托可被随意调用;若将委托定义为只写,虽可避免被随意调用,但将无法使用+=实现多播;
             */
            Read();
        }