.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));
上一篇:centos 6.5 yum安装 mysql 5.6


下一篇:UI设计文本框解决Placeholder的在IE10 以下 IE 9 IE8 IE 7 的兼容问题