Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Can I Get C# To Distinguish Between Ambiguous Class Names?

Tags:

c#

.net

How can I get C# to distinguish between ambiguous class types without having to specify the full HtmlAgilityPack.HtmlDocument name every time (it is ambiguous compared to System.Windows.Forms.HtmlDocument)?

Is there a way to make C# know that I am ALWAYS talking about one class or the other, and thus not have to specify it each time I use it?

like image 835
Alex Baranosky Avatar asked Jan 09 '09 07:01

Alex Baranosky


2 Answers

Use aliases:

using HapHtmlDocument = HtmlAgilityPack.HtmlDocument;
using WfHtmlDocument = System.Windows.Forms.HtmlDocument;
like image 81
Hosam Aly Avatar answered Oct 11 '22 12:10

Hosam Aly


You can define an alias for one namespace, e.g:

using hap = HtmlAgilityPack;

and then use the alias instead of the full namespace:

hap.HtmlDocument doc = new hap.HtmlDocument;
like image 38
M4N Avatar answered Oct 11 '22 13:10

M4N