-
Recently, I found the following behavior: X.M(0); // M(int)
X.M(default); // M(byte)
X.N(0); // N(byte?)
X.N(default); // N(byte?)
X.N(null); // N(byte?)
class X
{
public static void M(int i32) { }
public static void M(byte i8) { }
public static void N(int? i32) { }
public static void N(byte? i8) { }
} The question is:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
If my understanding of the spec is correct:
spec:
|
Beta Was this translation helpful? Give feedback.
-
OK, now I understood the following sentence inplies that narrower is better.
|
Beta Was this translation helpful? Give feedback.
If my understanding of the spec is correct:
0
isint
, thereforeM(0)
callsM(int)
.default
is notint
orbyte
,int?
orbyte?
,0
andnull
are notint?
orbyte?
, but all of them can be implicitly converted to the types, so they are resolved just like any other case where the expression converts to both types: the function whose parameter type implicitly converts to the parameter type of the other function is better.spec: