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的资料请关注自学编程网其它相关文章!
- 本文固定链接: https://zxbcw.cn/post/201550/
- 转载请注明:必须在正文中标注并保留原文链接
- QQ群: PHP高手阵营官方总群(344148542)
- QQ群: Yii2.0开发(304864863)