C# Language Passing null as one of the arguments


If you have

void F1(MyType1 x) {
    // do something

void F1(MyType2 x) {
    // do something else

and for some reason you need to call the first overload of F1 but with x = null, then doing simply


will not compile as the call is ambiguous. To counter this you can do

F1(null as MyType1);