您的位置:首页 > 其它

使用LINQ查询成绩合格的学生,并按照成绩降序排序。

2012-01-19 17:09 309 查看
学生成绩数据如下:

姓名 成绩

黄继祖 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();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐