Search code examples
c#nullambiguous-call

How to resolve ambiguity when argument is null?


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 convert null to any of those classes?

static void Main(string[] args)
{
    Func(null);
}

void Func(Class1 a)
{

}

void Func(Class2 b)
{

}

Solution

  • Func((Class1)null);