匿名类型与对象初始化器

    public class Person
    {
        public string Name { get; set; }
        public int Age { get; set; }
    }

  

            List<Person> people=new List<Person>
                (
                new[]
                {
                new Person{Name="1",Age=15},//初始化器
                new Person{Name="2",Age=18},
                new Person{Name="3",Age=54}
               }
            );

匿名类型

var o =new  { name = "123", value = "456" };

匿名类型数组

var ol = new[] { new{ name = "123", Value = "456" }, new{ name = "777", Value = "999" } };

  

 

posted @ 2019-06-05 15:16  xuelixue  阅读(173)  评论(0编辑  收藏  举报