dynamic 可在反射、json反序列化时使用、已达到减少代码量的效果。看代码
using System; namespace ConsoleApp2 { class Program { static void Main(string[] args) { System.Type t = typeof(Person); var obj = Activator.CreateInstance(t, null); t.InvokeMember("Talk", System.Reflection.BindingFlags.InvokeMethod, null, obj, new object[] { "hell world!" }); dynamic obj2 = Activator.CreateInstance(t, null); obj2.Talk("hell world!"); } } class Person { public void Talk(string msg) { Console.WriteLine(msg); } } }
//发送请求 string result = HttpUtil.HttpPost(uri, url, data, headerdata); Console.WriteLine("获取销售易表" + table + "数据:"); Console.WriteLine(result); //数据反序列化为匿名对象 var list = JsonConvert.DeserializeAnonymousType(result, new { records = new List<dynamic>() });
以上就是c# dynamic的好处的详细内容,更多关于c# dynamic的资料请关注其它相关文章!
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
评论(0)