A using directive has two uses:
The using keyword is also used to create a using statement that defines a scope that frees one or more objects from this scope.
See Using statement. http://www.yaosansi.com/blog/article.asp?id=669
Using namespace;using alias = Type|namespace;
Parameters
-
Alias
-
A user-defined symbol that you want to represent a namespace or type. You can then use the alias to represent the namespace name.
-
Type
-
The type you want to represent with the alias.
-
Namespace
-
The namespace that you want to represent through the alias. Or a namespace that contains types that you want to use without specifying a fully qualified name.
Note
The scope of the using directive is limited to the file containing it.
Create a using alias to make it easier to qualify identifiers to namespaces or types.
Create a using directive to use the type in a namespace without having to specify a namespace. The using directive does not give you access to any namespaces that are nested within the specified namespace.
Namespaces are grouped into two categories: User-defined namespaces and system-defined namespaces. A user-defined namespace is a namespace defined in code. To view a list of system-defined namespaces, see the. NET Framework Class Library Reference.
For an example of referencing a method in another assembly, see Creating and using a C # DLL.
Example 1
Description
The following example shows how to define and use a using alias for a namespace:
Code
Using Myalias = mycompany.proj.nested;//Define A alias to represent a namespace.namespace mycompany.proj{public class my Class{public static void Donothing () {}}}
Example 2
Description
The following example shows how to define a using directive and a using alias for a class:
Code
cs_using_directive2.cs//using directive.using system;//using alias for a class.using Aliastomyclass = Namespace1.mycl Ass;namespace Namespace1{public class Myclass{public override string ToString () {return ' You are in Namespace1.myclass ';}} }namespace namespace2{class myclass{}}namespace namespace3{//using directive:using namespace1;//using directive: Using Namespace2;class mainclass{static void Main () {Aliastomyclass Somevar = new Aliastomyclass (); Console.WriteLine (Somevar);}}
Output
are in Namespace1.myclass