O'Reilly logo

Programming Visual Basic .NET by Dave Grundgeiger

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

Namespaces

Thousands of types are defined in the .NET Framework. In addition, programmers can define new types for use in their programs. With so many types, name clashes are inevitable. To prevent name clashes, types are considered to reside inside of namespaces. Often, this fact can be ignored. For example, in Visual Basic .NET a class may be defined like this:

Public Class SomeClass
   ' ...
End Class

This class definition might be in a class library used by third-party customers, or it might be in the same file or the same project as the client code. The client code that uses this class might look something like this:

Dim x As New SomeClass(  )
x.DoSomething(  )

Now consider what happens if the third-party customer also purchases another vendor’s class library, which also exposes a SomeClass class. The Visual Basic .NET compiler can’t know which definition of SomeClass will be used. The client must therefore use the full name of the type, also known as its fully qualified name . Code that needs to use both types might look something like this:

' The namespace is "FooBarCorp.SuperFoo2100".
Dim x As New FooBarCorp.SuperFoo2100.SomeClass(  )
x.DoSomething(  )
' ...
' The namespace is "MegaBiz.ProductivityTools.WizardMaster".
Dim y As New MegaBiz.ProductivityTools.WizardMaster.SomeClass(  )
y.DoSomethingElse(  )

Note that a namespace name can itself contain periods (.). When looking at a fully qualified type name, everything prior to the final period is the namespace name. The name after ...

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