首页 > Windows开发 > 详细

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

时间:2015-12-10 16:44:53      阅读:260      评论:0      收藏:0      [点我收藏+]

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;
}

  

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

原文:http://www.cnblogs.com/hualiu0/p/5036137.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!