How do you resolve .Net namespace conflicts with the 'using' keyword?

Gishu picture Gishu · Sep 14, 2008 · Viewed 11.8k times · Source

Here's the problem, you include multiple assemblies and add 'using namespaceX' at the top of your code file.
Now you want to create a class or use a symbol which is defined in multiple namespaces, e.g. System.Windows.Controls.Image & System.Drawing.Image

Now unless you use the fully qualified name, there will be a crib/build error due to ambiguity inspite of the right 'using' declarations at the top. What is the way out here?

(Another knowledge base post.. I found the answer after about 10 minutes of searching because I didn't know the right keyword to search for)

Answer

aku picture aku · Sep 14, 2008

Use alias

using System.Windows.Controls;
using Drawing = System.Drawing;

...

Image img = ... //System.Windows.Controls.Image
Drawing.Image img2 = ... //System.Drawing.Image

How to: Use the Namespace Alias Qualifier (C#)