鑑於以下重載方法:重載方法選擇邏輯
public string Test(long item)
{
return "Test with a long was called!";
}
public string Test(int item)
{
return "Test with an int was called!";
}
public string Test(object item)
{
return "Test with an object was called!";
}
當我打電話Test()
,傳遞short
,像這樣:
short shortValue = 7;
var result = Test(shortValue);
爲什麼值result
等於"Test with an int was called!"
,而不是"Test with an object was called!"
?
+1 - 啊,認爲它寧願繼承轉換。很高興知道,感謝C#規範的鏈接。 –