TAILIEUCHUNG - Enabling Section

Enabling Notifications with Events In the previous section, you saw how to declare a delegate type, call a delegate, and create delegate instances. However, this is only half the story. | Enabling Notifications with Events In the previous section you saw how to declare a delegate type call a delegate and create delegate instances. However this is only half the story. Although delegates allow you to invoke any number of methods indirectly you still have to invoke the delegate explicitly. In many cases it would be useful to have the delegate run automatically when something significant happens. For example in the automated factory scenario it could be vital to be able to invoke the stopMachinery delegate and halt the equipment if a machine overheats. In the .NET Framework events allow you to define and trap significant actions and arrange for a delegate to be called to handle the situation. Many classes in the .NET Framework expose events. Most of the controls that you can place on a Windows form and the Windows Form class itself use events to allow you to run code when for example the user clicks a button or types something in to a field. You can also define your own events. 1. Locate the method. Comment out the throw new Exception statement. The enumerator does not use any resources that require explicit disposal so this method does not need to do anything. It must still be present however. For more information about the Dispose method refer to Chapter 13. 2. Build the solution and fix any errors that are reported. Initializing a Variable Defined with a Type Parameter You should have noticed that the statement that defines and initializes the currentItem variable uses the default keyword. This keyword is a new feature in C . The currentItem variable is defined by using the type parameter T. When the program is written and compiled the actual type that will be substituted for T might not be known this issue is only resolved when the code is executed. This makes it difficult to specify how the variable should be initialized. The temptation would be to set it to null. However if the type substituted for T is a value type then .

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.