O'Reilly logo

Professional Visual Basic 2012 and .NET 4.5 Programming by Todd Herman, Gastón Hillar, David McCarter, Rob Windsor, Billy Hollis, Bill Sheldon

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating Your Own Namespaces

Every assembly created in .NET is part of some root namespace. By default assemblies are assigned a namespace that matches the project name. In .NET it is possible to change this default behavior. Just as Microsoft has packaged the system-level and CLR classes using well-defined names, you can create your own namespaces. Of course, it is also possible to create projects that match existing namespaces and extend those namespaces, but that is typically a poor programming practice.

Namespaces can be created at one of two levels in Visual Basic. Similar to C# it is possible to explicitly assign a namespace within a source file using the Namespace keyword. However, Visual Basic provides a second way of defining your custom namespace. By default one of your project properties is the root namespace for your application in Visual Basic. This root namespace will be applied to all classes that don't explicitly define a namespace. You can review your project's default namespace by accessing the project properties. This is done through the assembly's project pages, reached by right-clicking the solution name in the Solution Explorer window and working off the first tab (Application) within the Properties page that opens in the document window, as shown in Figure 2.11.

Figure 2.11 Application settings in project properties

2.11

The next step is optional, but, depending ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required