I have discovered by error something that surprised me.
I have this method
public static string PrintDecimal(decimal? input, string NumberFormat = null){ }
And I call this method like this
int? MaxFaltas = 0;
Label.Text = CustomConvert.PrintDecimal(MaxFaltas);
Why this is working and there are no compilation errors. I'm calling a method witch is defined to receive a decimal?
with a int?
You just discovered something described in the spec as lifted operators.
They let you convert Nullablt<A>
to Nullable<B>
as long as A
can be converted to B
.
6.4.2 Lifted conversion operators
Given a user-defined conversion operator that converts from a non-nullable value type
S
to a non-nullable value typeT
, a lifted conversion operator exists that converts fromS?
toT?
. This lifted conversion operator performs an unwrapping fromS?
toS
followed by the user-defined conversion fromS
toT
followed by a wrapping fromT
toT?
, except that anull
valuedS?
converts directly to anull
valuedT?
.