学生成绩数据如下:
姓名 成绩
黄继祖 80
李小悦 55
张文驹 90
吴俊祥 76
郭 郭 53
唐卫东 98
建一个Web应用程序,添加一个GridView1控件,
Student.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace LINQApp
{
//========================================================================
// クラス名 : Student
/// <summary>
/// Student
/// </summary>
/// <remarks>
/// 给Student设置两个属性Name,Scores
/// </remarks>
//========================================================================
public class Student
{
/// <summary>Nameを設定/取得する</summary>
/// <value></value>
public string Name
{
get;
set;
}
/// <summary>Scoresを設定/取得する</summary>
/// <value></value>
public int Scores
{
get;
set;
}
}
}
protected void Page_Load(object sender, EventArgs e)
{
List<Student> students = new List<Student>
{
new Student{Name="黄继祖",Scores=80},
new Student{Name="李小悦",Scores=55},
new Student{Name="张文驹",Scores=90},
new Student{Name="吴俊祥",Scores=76},
new Student{Name="郭 郭",Scores=53},
new Student{Name="唐卫东",Scores=98}
};
var studentQuery = from student in students
where student.Scores >= 60
orderby student.Scores descending
select student;
GridView1.DataSource = studentQuery;
GridView1.DataBind();
}