码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2015-12-10 16:46:29      阅读:202      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!