Namespaces
A namespace helps you to divide and conquer the complexity of the object hierarchy.
The .NET Framework organises its classes into namespaces
examples SS
Avoid defining types in the global namespace
The same namesapce can exist in multiple files
It is possible to nest namespace declarations
A collection of logically related types
Namespaces can be nested
avoids name conflicts
can include dots to indicate a hierarchical structure
namespace Better1
{
namespace MyDataStructures
{
namespace MyArrays
{
}
}
}
is the same as
namespace Better1.MyDataStructures.MyArrays
{
}
Qualified names can be broken after a dot (.) if they are too long for a single line, as shown in the following example.
Default / Global Namespace
Any classes or code that is not explicitly added to an explicit namespace is contained in the global namespace
Everything is an object that derives from the root class System.Object
Microsoft.CSharp namespace
This namespace contains classes that support compilation and code generation using th C# language.
using Directive
If you are using several objects from the same namespace you can save typing by adding the necessary using directive to the top of your program
If you do not want to fully qualify your namespaces you can use the using directive.
This provides a way of importing a namespace so it does not have to be fully qualified.
The main use of the using directive is to be able to refer to types without having to fully qualify them all.
using System
Using Alias Directive
This can be used to create an alias for a namespace or a type.
The right side of a using alias directive must always be fully qualified.
using Excel = Microsoft.Office.Interop.Excel
Static Members
You often find yourself repeating the class name as a prefix for the static members.
using static System.Console;
using static System.Math;
WriteLine("some text");
Sqrt(4);
instead of
using System.Console;
using System.Math;
Console.WriteLine("some text")
Math.Sqrt(4);
Using Statement
The using directive is not to be confused with the Using Statement which is used for defining the scope of objects.
Using Directive
Imports System
Using Alias Directive
Imports Excel = Microsoft.Office.Excel
© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext