Accelerated VB 2005 phần 7

Lưu ý rằng trong việc hình thành chuỗi, các loại đã sử dụng CurrencyDecimalSeparator, CurrencyDecimalDigits, và tính chất CurrencySymbol của thể hiện NumberFormatInfo trở về từ phương pháp . | CHAPTER 12 Delegates and Events D elegates provide a built-in language-supported mechanism for defining and executing callbacks. Their flexibility allows you to define the exact signature of the callback and that information becomes part of the delegate type itself. Anonymous functions are forms of delegates that allow you to shortcut some of the delegate syntax that in many cases may be overkill. Building on top of delegates is the support for events in Visual Basic VB and the .NET platform. Events provide a uniform pattern for hooking up callback implementations and possibly multiple instances thereof to the code that triggers the callback. Overview of Delegates The common language runtime CLR provides a runtime that supports a flexible callback mechanism and delegates are the preferred method of implementing these callbacks. When you declare a delegate in your code the VB compiler generates a class derived from MulticastDelegate and the CLR implements all of the interesting methods of the delegate dynamically at run time. The delegate contains a couple of useful fields. The first one holds a reference to an object and the second holds a method pointer. When you invoke the delegate the instance method is called on the contained reference. However if the object reference is Nothing the runtime understands this to mean that the method is a shared method. One delegate type can handle callbacks to either an instance or shared method. Moreover invoking a delegate is exactly the same syntactically as calling a regular function. Therefore delegates are perfect for implementing callbacks. As you can see delegates provide an excellent mechanism to decouple the method being called on an instance from the actual caller. In fact the caller of the delegate has no idea or necessity to know if it is calling an instance method or a shared method or on what exact instance it is calling. To the caller it is calling arbitrary code. The caller can obtain the delegate instance .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã 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.