14.1. What Is the My Namespace?

The My namespace is actually a set of wrapper classes and structures that encapsulate complete sets of .NET classes and automated object instantiations and initializations. The structure of My, shown in Figure 14-1, shows that it is similar to a real namespace hierarchy. These classes mean that rather than creating an instance of a system class, initializing it with the values you need, and then using it for the specific purpose you need it for, you can simply refer to the corresponding My class and let .NET work out what needs to happen behind the scenes to achieve the same result. Consider more complex tasks that require you to create up to dozens of classes to do something simple, such as establish user credentials or navigate through the file system efficiently. Then consider the same one-class access that My provides for such functions, and you begin to see what can be achieved.

Figure 14.1. Figure 14-1

Ten major classes compose the top level of My. Each class has a number of methods and properties that you can use in your application, and two of them, My.Application and My.Computer, have additional subordinate classes in the namespace-like structure, which in turn have their own methods and properties. In a moment you'll see what each of them can do in detail, but here's a quick reference:

Table 14.1. Classes in the Top Level of My
My Object ...

Get Professional Visual Studio® 2008 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.