Saturday, January 17, 2009

using Directive in C#

using Directive:
Basically it allows to the coder to use various objects, types or classes available in a name space whitout fully qualifying the object. this will reduce the code drastically if you are having some great number of lines being coded.

using Directive is totally different from using Statement in C# and it has two very basic usages

1) user do not have to qualify the use of a type in that namespace.
For example:

using System.Text;
StringBuilder sbTest = new StringBuilder();

instead of writing the whole namespace.
System.Text.StringBuilder sbTest = new System.Text.StringBuilder();

2) It allows to create an alias for a namespace need to be used.
For example:

using DAL = MyCompany.MyProject.DAL;


* It can't be used out side of file its being declared. The scope is limited to the file in which it is being declared
* The using keyword is also used to create using statements.

No comments:

Post a Comment