.net 关于匿名类型的特性

匿名类型

   1: var n1 = new { name = "name1", age = 40 };

   2: var n2 = new { name = "name2", age = 31 };

   3: var n3 = new { name = "name3", age = 32 };

   4: Console.WriteLine("{0} is {1} years old",n1.name,n1.age);

 结合数组应用

var family = new[]
{
    new { name = "Holly", age = 31 },
    new { name = "Jon", age = 31 }
};

 结合序列化

var list = new List<object>();
for (int i = 0; i < id_arrt.Length; i++)
{
    list.Add(new { Name = "Tom", Age = 4 });
}
context.Response.Write(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(list));

 

posted @ 2014-11-04 16:59  microsoftzhcn  阅读(370)  评论(0编辑  收藏  举报