c# dynamic,maybe I should say it is just some shortcut for "Object", box and unbox, without the cast

dynamic:

void Main()
{
 var b="2";
 dynamic a="2";
 if(a.GetType()==typeof(int))b+=a;
 if(a.GetType()==typeof(string))b+=a;
 Console.WriteLine (b);
 Console.WriteLine (GetName(1));
 Console.WriteLine (GetName(2));
}

// Define other methods and classes here
dynamic GetName(int a){
dynamic ret;
if(a==1)ret=2;
else ret="b";
return ret;
}

  

posted @ 2015-12-10 15:13  calochCN  阅读(113)  评论(0编辑  收藏  举报