TAILIEUCHUNG - Delegates and Events

Classes are reference types that allow you to create instances of objects and use them in special ways to meet your application’s requirement. Another reference type in C# is delegate. Delegates allow you to change the reference to a method at runtime. This means that you can decide the execution of a method at run-time, based on the requirements of your application. The method can be activated at the occurrence of an event, where an event is associated with the delegate to call the method at run-time. . | Delegates and Events Chapter 12 Classes are reference types that allow you to create instances of objects and use them in special ways to meet your application s requirement. Another reference type in C is delegate. Delegates allow you to change the reference to a method at runtime. This means that you can decide the execution of a method at run-time based on the requirements of your application. The method can be activated at the occurrence of an event where an event is associated with the delegate to call the method at run-time. This chapter discusses the creation of delegates. This chapter also discusses how to implement multicast delegates. In addition it discusses how you can use events with delegates. Objectives In this chapter you will learn to fl Implement delegates fl Implement multicast delegates fl Use events with delegates Introducing Delegates Delegates in C allow you to dynamically change the reference to the methods in a class. Consider an example of a coffee vending machine which dispenses different flavors of coffee such as cappuccino and black coffee. On selecting the desired flavor of coffee the vending machine decides to dispense the ingredients such as milk powder coffee powder hot water cappuccino coffee powder. All the materials are placed in different containers inside the vending machine. The required material is dispensed when you select a flavor. Suppose you select black coffee the vending machine will call methods to dispense hot water and coffee powder only. The reference to these methods is made dynamically when you press the required button to dispense black coffee. A delegate is a reference type variable which holds the reference to a method. This reference can be changed at runtime as desired. Although delegates are a general-purpose mechanism for indirectly calling methods at runtime their primary use in C programming is for implementing events and the call-back methods. To implement delegates in your application you need to .

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.