Passing null as one of the arguments C# with Example



Passing null as one of the arguments C# with Example

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 
F1(null); 
will not compile as the call is ambiguous. To counter this you can do 
F1(null as MyType1); 
 

0 Comment's

Comment Form

Submit Comment