可能重複:
C#: Passing null to overloaded method - which method is called?方法重載和空值
考慮以下2種方法:
void Method(object obj) { Console.WriteLine("object"); }
void Method(int[] array) { Console.WriteLine("int[]"); }
當我嘗試打電話:
Method(null);
在Visual Studio 2008 SP1我得到int[]
。
這是爲什麼?
他可能會問爲什麼編譯器支持過載。 – Vlad
他的問題是爲什麼重載分辨率解析爲null的方法需要一個int數組而不是採用對象的方法。 –
看到這個問題:http://stackoverflow.com/q/719546/25727 – Jan