How to resolve ambiguity when argument is null?

后端 未结 7 1617
轮回少年
轮回少年 2021-01-03 19:36

Compiling the following code will return The call is ambiguous between the following methods or properties error. How to resolve it since I can\'t explicitly co

7条回答
  •  温柔的废话
    2021-01-03 20:28

    Just an alternative solution I prefer

    static void Main(string[] args)
    {
        Func(Class1.NULL);
    }
    
    void Func(Class1 a)
    { }
    
    void Func(Class2 b)
    { }
    
    class Class1
    {
        public static readonly Class1 NULL = null;
    }
    
    class Class2
    {
        public static readonly Class2 NULL = null;
    }
    

提交回复
热议问题