Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Aliasing / Shortening the Namespaces in .NET

Tags:

c#

.net

There are two namespaces with class Image. One is iTextSharp and another WPF System.Windows.Control.Image.

Now I've to use complete reference i.e. System.Windows.Control.Image a = new .. and iTextSharp.text.Image b = new ...

Is there any way to Aliasing the namespace, so I don't have to write complete namespace.

like image 289
asifabbas Avatar asked Nov 05 '10 06:11

asifabbas


People also ask

How do you shorten a namespace in C#?

C# namespace aliasing The using keyword can be used to create an alias for a namespace. With nested namespaces, the fully qualified names might get long. We can shorten them by creating aliases. In the example, we create an alias for a Book class that is enclosed by two namespaces.

What is namespace aliases in C#?

Namespaces in C# serve two main purposes: to organize classes and functionality and to control the scope of classes and methods. Type aliasing is a little known feature for C# and it comes in handy when you would like to alias a specific method or class from a namespace for the sake of clarity.

What are the .NET namespaces?

Namespaces are used to organize the classes. It helps to control the scope of methods and classes in larger . Net programming projects. In simpler words you can say that it provides a way to keep one set of names(like class names) different from other sets of names.


2 Answers

Yeps, just use:

using Img = System.Windows.Control.Image;

In your namespace declaration.

Then you can use the Img aliased name as you used the fully qualified name previously.

like image 117
Kyle Rosendo Avatar answered Oct 19 '22 12:10

Kyle Rosendo


Try:

using yourAlias = System.Windows.Control.Image;
like image 28
Dies Avatar answered Oct 19 '22 11:10

Dies