声明为动态的变量和声明为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