asp.net学习笔记 linq查询用法
2014-01-28 00:00
501 查看
linq查询 大概这个样子
解读成 select student from students where student.Scores[0]>90;
例子
IEnumerable<Student> studentQuery = from student in students where student.Scores[0] > 90 select student;
解读成 select student from students where student.Scores[0]>90;
例子
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class linq_test : System.Web.UI.Page { //定义一个数据 static List<Student> students = new List<Student> { new Student {First="Svetlana", Last="Omelchenko", ID=111, Scores= new List<int> {97, 92, 81, 60}}, new Student {First="Claire", Last="O'Donnell", ID=112, Scores= new List<int> {75, 84, 91, 39}}, new Student {First="Sven", Last="Mortensen", ID=113, Scores= new List<int> {88, 94, 65, 91}}, new Student {First="Cesar", Last="Garcia", ID=114, Scores= new List<int> {97, 89, 85, 82}}, new Student {First="Debra", Last="Garcia", ID=115, Scores= new List<int> {35, 72, 91, 70}}, new Student {First="Fadi", Last="Fakhouri", ID=116, Scores= new List<int> {99, 86, 90, 94}}, new Student {First="Hanying", Last="Feng", ID=117, Scores= new List<int> {93, 92, 80, 87}}, new Student {First="Hugo", Last="Garcia", ID=118, Scores= new List<int> {92, 90, 83, 78}}, new Student {First="Lance", Last="Tucker", ID=119, Scores= new List<int> {68, 79, 88, 92}}, new Student {First="Terry", Last="Adams", ID=120, Scores= new List<int> {99, 82, 81, 79}}, new Student {First="Eugene", Last="Zabokritski", ID=121, Scores= new List<int> {96, 85, 91, 60}}, new Student {First="Michael", Last="Tucker", ID=122, Scores= new List<int> {94, 92, 91, 91} } }; protected void Page_Load(object sender, EventArgs e) { //查询 IEnumerable<Student> studentQuery = from student in students where student.Scores[0] > 90 select student; //遍历 foreach (Student student in studentQuery){ Response.Write(student.ID+"<br/>"); } var a = 12; } public class Student { //调用方法 public string First { get; set; } public string Last { get; set; } public int ID { get; set; } public List<int> Scores; } }
相关文章推荐
- ASP.NET 3.5核心编程学习笔记(21):LINQ查询语法
- ASP.NET 3.5核心编程学习笔记(22):LINQ与SQL的交互、延迟加载与预加载
- ASP.NET学习笔记---数据查询与展示:DataList
- ASP.NET学习笔记---- 数据查询与展示GridView
- ASP.NET学习笔记---- 数据查询与展示GridView
- ASP.NET 3.5核心编程学习笔记(23):Linq-to-SQL 数据的更新、事务、存储过程、函数
- ASP.NET学习笔记[8] - 梅花雨日历控件与textbox控件用法
- asp.net Linq to Xml学习笔记
- 黑马程序员之ASP.NET学习笔记: 分享Asp.net中具体的日期格式化用法
- ASP.NET中Linq查询数据的用法
- ASP.Net MVC开发基础学习笔记(7):数据查询页面
- 【Pro ASP.NET MVC 3 Framework】.学习笔记.5.SportsStore一个真实的程序
- Asp.Net Ajax 学习笔记21 VS2008的JavaScript代码提示功能
- ASP.NET MVC Web API 学习笔记---联系人增删改查
- ASP.NET 3.5核心编程学习笔记(9):用户配置文件
- ASP.NET 3.5核心编程学习笔记(10):母版页
- Asp.net控件开发学习笔记(四)---Asp.net服务端状态管理
- asp .net学习笔记之使用jmail发送邮件
- Asp.net控件开发学习笔记(五)---Asp.net客户端状态管理