public class students
{
public string Name { get; set; }
public string Age { get; set; }
}
protected void Page_Load(object sender, EventArgs e)
{
//创建数据源
ArrayList arraylist = new ArrayList();
arraylist.Add(new students
{
Name = "王成",
Age ="男"
});
arraylist.Add(new students
{
Name = "张想",
Age ="女"
});
arraylist.Add(new students
{
Name = "叶志",
Age ="男"
});
arraylist.Add(new students
{
Name = "周斌",
Age ="女"
});
//创建查询
var studentQuery = from students student in arraylist group student by student.Age;
foreach (var stuquery in studentQuery)
{
Response .Write (stuquery.Key+"<br/>");
foreach (students stu in stuquery)
{
Response.Write(stu.Name);
}
Response.Write(stuquery.Count() + "<br/>");
}
}