tailieunhanh - Remember Interfacing Working
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. | 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
đang nạp các trang xem trước