Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: .NET
Expertise: Intermediate
Apr 18, 2007



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Using Namespace Aliases in .NET

In most cases, when there are namespace conflicts, developers tend to use the complete qualified name in the code. For example:

using System.Web.UI.WebControls;
using MyComponent.Web.UI.WebControls;
This is usually okay for simple class files—assuming that there is a Calendar class in both namespaces and you need to use the custom class in many sections of the class.

However, instead of specifying the fully qualified name, you could also give an alias for the namespace and make use of it everywhere, like this:

using System.Web.UI.WebControls;
using MyControls = MyComponent.Web.UI.WebControls;
Then, instead of using the fully-qualified name like this:

MyComponent.Web.UI.WebControls.Calender cal = 
new MyComponent.Web.UI.WebControls.Calender();
You'd be able to use the shorter aliased name, like this:

MyControls.Calender  cal = new MyControls.Calender();

Jayadev D
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date