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

后端 未结 3 669
遥遥无期
遥遥无期 2021-02-07 08:21

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 compa

相关标签:
3条回答
  • 2021-02-07 08:55

    Use aliases:

    using HapHtmlDocument = HtmlAgilityPack.HtmlDocument;
    using WfHtmlDocument = System.Windows.Forms.HtmlDocument;
    
    0 讨论(0)
  • 2021-02-07 08:57

    Declare conflicting namespaces at different levels, most inner one will be used without ambiguity:

    using System.Windows.Forms;
    
    namespace MyNamespace {
        using HtmlAgilityPack;
    
        public class Class1 {
            private HtmlDocument _doc; // HtmlAgilityPack.HtmlDocument
        }
    
    0 讨论(0)
  • 2021-02-07 09:03

    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;
    
    0 讨论(0)
提交回复
热议问题