Question
How come Nullable<int> can be converted to IFormattable though Nullable<int> not implementing IFormattable
I can confirm that int?
type does not implement IFormattable
by examining the following code:
var doesImplement = typeof(Nullable<long>).GetInterface(nameof(IFormattable)) != null;
Now that we are sure int?
is not IFormattalbe
why does the following code works?
int? a = 11111;
var formatted = ((IFormattable)a)?.ToString("N0",null)
// formatted is 11,111
Is there any explicit conversion defined somewhere? If yes, where?
3 36
3