Importing nested namespaces automatically in C#

C# is not Java.

A using directive is used so you don’t have to type in the fully qualified name of a type. It also helps with disambiguating type names (using aliases for instance).

In the case of Console, for example, you don’t need to type System.Console.

It is important to understand the difference between a namespace and an assembly – a namespace is a logical grouping of types. An assembly is a physical grouping of types. Namespaces can span assemblies.

When you reference an assembly (this is more like importing a package in Java), you gain access to all of the public types in it. In order to use a type you need to uniquely identify it. This is done through the namespace – the using directive simply means you don’t have to type the fully qualified name of the type.

Leave a Comment