Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Nếu phương pháp này có một tài sản, bạn có thể khai báo nó như là một phần của giao diện bằng cách sử dụng từ khóa bất động sản: Bạn cũng có thể khai báo các sự kiện như là một phần của giao diện bằng cách sử dụng từ khóa sự kiệnĐể bao gồm một phương pháp như là một phần của giao diện của bạn, bạn chỉ đơn giản | Chapter 9 Figure 9-8 My The My keyword is a novel concept to quickly give you access to your application your users your resources the computer or the network on which the application resides. The My keyword has been referred to as a way of speed-dialing common but complicated resources that you need access to. Using the My keyword you can quickly get access to a wide variety of items such as user details or specific settings of the requestor s browser. Though not really considered a true namespace the My object declarations that you make work the same as the .NET namespace structure you are used to working with. To give you an example let s first look at how you get at the user s machine name using the traditional namespace structure Environment.MachineName.ToString For this example you simply need to use the Environment class and use this namespace to get at the MachineName property. Now let s look at how you would accomplish this same task using the new My keyword My.Computer.Info.MachineName.ToString As you are looking at this example you might be wondering what the point is if the example which is using My is lengthier than the first example that just works off of the Environment namespace. Just remember that it really isn t about the length of what you type to get access to specific classes but instead is about a logical way to find often accessed resources without the need to spend too much time hunting them down. Would you have known to look in the Environment class to get the machine name of the user s computer Maybe but maybe not. Using My.Computer.Info.MachineName.ToString is a tremendously more logical approach and once compiled this namespace declaration will be set to work with the same class as previously without a performance hit. 298 Namespaces If you type the My keyword in your Windows Forms application you will notice that IntelliSense provides you with six items to work with Application Computer Forms Resources User and WebServices. Though this