tailieunhanh - Declaring Interface Properties

Kê khai giao diện Properties Bạn đã gặp các giao diện tại Chương 12, "Làm việc với Inheritance" giao diện. Cũng có thể chỉ định tài sản. Để làm điều này, bạn khai báo nhận được, hoặc thiết lập từ khóa, hoặc cả hai, 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. | Declaring Interface Properties You met interfaces in Chapter 12 Working with Inheritance. Interfaces can also specify properties. To do this you declare the get or set keyword or both but replace the body of the get or set accessor with a semicolon. For example interface IScreenPosition int X get set int Y get set Any class or struct that implements this interface must implement the accessors. For example struct ScreenPosition IScreenPosition . public int X get . set . public int Y get . set . . If you implement the interface properties in a class you can declare the property implementations as virtual which allows further derived classes to override the implementations. For example class ScreenPosition IScreenPosition . public virtual int X get . set . public virtual int Y get . set . . NOTE The example shows a class. Remember that the virtual keyword is not valid in structs because you can t derive from structs structs are implicitly sealed. You can also choose to implement a property by using the explicit interface implementation syntax covered in Chapter 12. An explicit implementation of a property is non-public and non-virtual and cannot be overridden . For example struct ScreenPosition IScreenPosition int get . set . int get . set . . private int x y Using Properties in a Windows Application When you use the Properties window in Microsoft Visual Studio 2005 you are actually generating code that sets and retrieves the values of properties of various application components items such as TextBox controls Forms and Button controls. Some components have a large number of properties although some properties are more commonly used than others. You can modify many of these properties at runtime by using the same syntax you have seen throughout this chapter. In the following exercise you will use some predefined properties of the TextBox controls and the Form class to create a simple application that continually displays the size of

TÀI LIỆU MỚI ĐĂNG
crossorigin="anonymous">
Đã 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.