C#中的匿名类型

匿名类的用法

class Test

{

public static void Main()

{

         var a = new 

                {
                      MyProperty1 = 1,
                      MyProperty2 = 2
                };
                Console.WriteLine(a.MyProperty1 + a.MyProperty2);
                Console.WriteLine(a.GetType());
                Console.ReadKey();

 

 

    class A
    {
        public int MyProperty1 { get; set; }
        public int MyProperty2 { get; set; }

    } 

这样真的可行啊!!运行后可以发现该对象的类型就是匿名类型的,还有你匿名的方法稍后再来讲解

 

posted @ 2012-03-24 18:58  张小然  阅读(282)  评论(0编辑  收藏  举报