聲明爲動態的變量和聲明爲System.Object的變量之間有什麼區別?運行下面的功能似乎表明,這兩個變量會馬上轉換爲動態的正確類型:動態和System.Object之間的區別
void ObjectTest()
{
System.Object MyTestVar = "test";
dynamic MyTestVar2 = "Testing 123";
Console.WriteLine("{0}", MyTestVar.GetType());
Console.WriteLine("{0}", MyTestVar2.GetType());
MyTestVar = 123;
MyTestVar2 = 321;
Console.WriteLine("{0}", MyTestVar.GetType());
Console.WriteLine("{0}", MyTestVar2.GetType());
}
前段時間我寫了一篇關於這個帖子的文章:http://blogs.msdn.com/b/csharpfaq/archive/2010/01/25/what-is-the-difference-between-dynamic-and-object -keywords.aspx – 2010-08-12 21:15:37