Home  |  Contact us    
Alias for namespace or class in C#


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

Use the using directive to create an alias for a long namespace or class. 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 obj; // Equivalent to System.Runtime.Remoting.Activation.UrlAttribute obj






Category: OOPS Faqs Concepts Faqs, Interview Questions & Answers in C#



Ask New Questions
Microsoft.Net Framework
.Net 2.0 Namespaces
.Net Assemblies
OOPS Faqs in C#
ASP.Net Faqs
ASP.Net 2.0 Faqs
Web Services Faqs
ADO.Net Faqs
Database Faqs
OOPS Faqs
IT Project Management