匿名类的使用及原理

 

 

 

 

 

 

 

 

 

新建一个匿名的类的对象

 

static void Main(string[] args)
        {
            var person = new { Name = "张三", Age = 12,Score=99 };
            Console.WriteLine(person.Name);
            Console.WriteLine(person.Age);
            Console.WriteLine(person.Score);
            Console.ReadKey();
        }

在使用过程中,并不需要提供类名,而是使用ver去代替

为什么说这个过程创建了匿名类呢?

打开.NEF Reflector

 

 

 

 

 

 

 

可以看出,生成了一个密封类。

posted @ 2018-01-30 17:56  一年变大牛  阅读(325)  评论(0编辑  收藏  举报