TAILIEUCHUNG - Teach Yourself the C# Language in 21 Days phần 7

Nếu xử lý nhiều sự kiện được gán cho một sự kiện, không có bảo đảm mà sẽ được thực hiện đầu tiên. Trong Liệt kê 13,5, không có đảm bảo rằng Change_A sẽ thực thi trước khi Change_D. Ngoài ra, xử lý sự kiện và các sự kiện có thể ném ngoại lệ và làm tất cả các mã khác có thể làm. | Making Your Programs React with Delegates Events and Indexers 461 D s are good Z Removing event handler. D Don t like a X d Analysis As you can see by the output when Line 22 is executed the change_D event is no longer active. However the change_A event handler continues to work. Caution If multiple event handlers are assigned to an event there is no guarantee for which will be executed first. In Listing there is no guarantee that Change_A will execute before Change_D. Additionally event handlers and events can throw exceptions and do all the things other code can do. If an exception is thrown there is no guarantee that other event handlers will be executed. Summary In today s lesson you learned about some of the more complicated topics within C . You first learned about indexers. Indexers can be used with a class so that you can access the class using index notation. This makes your classes arraylike. You then learned about delegates. You learned that delegates are like interfaces They state a definition for accessing but don t actually provide the implementation. Delegates set up a format for using methods. You learned that a delegate can be used to dynamically call different methods with a single method call. The last part of today s lesson focused on events. You learned that code can be created to cause an event to happen. More important you learned that code event handlers can be created to react when an event happens. q a Q Today s concepts were hard. How important is it to understand them A You can do a lot with C without understanding the concepts presented today however there is a lot more that you won t be able to do. If you plan to program applications for Windows or other graphical environments you will find that events are critical. And as you learned today delegates are critical for working with events. 13 462 Day 13 Many of the C editors such as Visual Studio .NET will help by automatically creating a lot of the code for you. For example Visual

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.