匿名对象解析
程序员文章站
2022-07-05 18:57:35
class Program { static void Main(string[] args) { List obj = new List(); obj.Add(new { aa=1,bb=1}); obj.Add(new { aa = 1, bb = 2 }); ... ......
class Program { static void Main(string[] args) { List<object> obj = new List<object>(); obj.Add(new { aa=1,bb=1}); obj.Add(new { aa = 1, bb = 2 }); var objs = obj.Select(t => t.Cast(new { aa = 0, bb = 0 })).ToList(); Console.ReadKey(); } } static class Extensions { public static T Cast<T>(this object obj, T sample) { return (T)obj; } }