C# FAQ: How use an alias for a class or namespace


Jump to: navigation, search
CSharp-Online.NET:FAQs
edit

How use an alias for a class or namespace?

The using directive can be used to create an alias for a long class name or a namespace. Then, the alias can be used instead—anywhere the class name or namespace could normally appear.

The using alias is scoped within the namespace in which it is declared. The following is an example of a using alias:

// Namespace alias example
using activation = System.Runtime.Remoting.Activation;
 
// Class name alias example
using arrayList = System.Collections.ArrayList;
 
// use the aliases ...
 
arrayList aList = new arrayList();      // creates an ArrayList
 
activation.UrlAttribute urlAttribute;   // is equivalent to ...
// System.Runtime.Remoting.Activation.UrlAttribute urlAttribute; 

See also



Personal tools