How do I use an alias for a namespace or class?

How do I use an alias for a namespace or class?

Rate This
  • Comments 6

Use the using directive to create an alias for a long namespace or class name. You can then use it anywhere you normally would have used that class or namespace. The using alias has a scope within the namespace you declare it in. Sample code:

// Namespace:
using act = System.Runtime.Remoting.Activation;
// Class:
using list = System.Collections.ArrayList;
...
list l = new list(); // Creates an ArrayList
act.UrlAttribute foo; // Equivalent to System.Runtime.Remoting.Activation.UrlAttribute foo

[Author: Jon Skeet]

Leave a Comment
  • Please add 7 and 3 and type the answer here:
  • Post
Page 1 of 1 (6 items)