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.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.


© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext