C# Bible 2002 phần 5

Tham khảo tài liệu 'c# bible 2002 phần 5', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | This error message states that the code is trying to derive an interface from itself which is not allowed in C . Interfaces can only be derived from other interfaces. Using the new Keyword to Reuse Identifiers You can use the new keyword to redefine an identifier used in a base class. Suppose you are working with an interface that defines a property called ID interface Baseinterface int ID get Now suppose that you d like to derive from that interface but you d like to use the ID identifier as the name of a method interface Derivedinterface Baseinterface int ID This construct causes the C compiler to issue a warning relating to the reuse of the identifier ID warning CS0108 The keyword new is required on because it hides inherited member The compiler is warning that the identifier ID is used twice once in the base interface as a property identifier and once in the derived interface as a method name. This name reuse will most likely be confusing to users of the interface. The compiler warning means that the use of the ID keyword in the derived interface takes precedence over the use of the ID keyword in the base interface. If a piece of code obtains an implementation of the DerivedInterface interface the code is unable to call the ID method but cannot access the ID property in the base interface. The reuse of the ID identifier in the derived interface hides the ID identifier in the base class and clients cannot access the base interface s property. To work around this issue you can use the keyword new when the identifier is reused. This use of the new keyword shown in the following example tells the C compiler that you intend to provide a new usage for the reused symbol interface Derivedinterface Baseinterface new int iD Implementing Interfaces in Classes and Structures After an interface is defined you can implement the interface in your C classes and structures. Implementing an interface on a class or structure tells users of the

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.