Indexers in Interfaces

Indexers trong giao diện Bạn có thể khai báo indexers trong một giao diện. Để làm điều này, chỉ rõ có được và / hoặc từ khóa được thiết lập, nhưng thay thế cho cơ thể của việc được, hoặc thiết lập accessor với dấu chấm phẩy. Bất kỳ lớp học hoặc struct mà thực hiện các giao diện phải thực hiện accessors indexer kê khai trong giao diện. | Indexers in Interfaces You can declare indexers in an interface. To do this specify the get and or set keyword but replace the body of the get or set accessor with a semicolon. Any class or struct that implements the interface must implement the indexer accessors declared in the interface. For example interface IRawInt bool this int index get set struct RawInt IRawInt . public bool this int index get . set . . If you implement the interface indexer in a class you can declare the indexer implementations as virtual. This allows further derived classes to override the get and set accessors. For example class RawInt IRawInt . public virtual bool this int index get . set . . You can also choose to implement an indexer by using the explicit interface implementation syntax covered in Chapter 12 Working with Inheritance. An explicit implementation of an indexer is non-public and non-virtual and so cannot be overridden . For example struct RawInt IRawInt . bool int index get . set . .

Bấm vào đây để xem trước nội dung
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.