1
簡單代碼:奇怪的動態類型參數的問題
class Program
{
static void Main(string[] args)
{
dynamic income = "test";
var result = Test(income); // Why dynamic?
Test2(result); // WTF?
}
static string Test(string income)
{
return income;
}
static string Test2(int income)
{
return income.ToString();
}
}
上面的代碼編譯沒有錯誤,並在運行時異常執行:An unhandled exception of type Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' occurred in System.Core.dll
任何人都可以解釋爲什麼result
被確定爲dynamic
類型?
它是否記錄在任何地方? –
這是'dynamic'核心行爲的一部分;看看它的文檔。 – SLaks