《心理素质训练》(PPT_85).ppt由 NordriDesign 提供# 基础教程查询训练创建项目及数据源 1 ? new Student {First="Fadi", Last="Fakhouri", ID=116, Scores= new List {99, 86, 90, 94}}, ? new Student {First="Hanying", Last="Feng", ID=117, Scores= new List {93, 92, 80, 87}}, ? new Student {First="Hugo", Last="Garcia", ID=118, Scores= new List {92, 90, 83, 78}}, ? new Student {First="Lance", Last="Tucker", ID=119, Scores= new List {68, 79, 88, 92}}, ? new Student {First="Terry", Last="Adams", ID=120, Scores= new List {99, 82, 81, 79}}, ? new Student {First="Eugene", Last="Zabokritski", ID=121, Scores= new List {96, 85, 91, 60}}, ? new Student {First="Michael", Last="Tucker", ID=122, Scores= new List {94, 92, 91, 91} } ?}; ?将新 Student 添加到 Students 列表中并使用我们选择的姓名和测验分数。尝试键入新学生的所有信息,以便更好地了解对象初始值设定项的语法。? 创建查询?在应用程序的 Main 方法中创建一个简单查询,执行该查询时,将生成第一次测验中分数高于 90 分的所有学生的列表。?请注意,由于选择了整个 Student 对象,因此查询的类型是 IEnumerable 。虽然代码也可以通过使用 var 关键字来使用隐式类型,但这里使用了显式类型以便清楚地演示结果。?另请注意,该查询的范围变量 student 用作对源中每个 Student 的引用, 以提供对每个对象的成员访问。? var studentQuery =from student in students where [0] > 90 ? select student; ? 执行查询?现在编写用于执行查询的 foreach 循环。请注意有关代码的以下事项: ?·所返回序列中的每个元素是通过 foreach 循环中的迭代变量来访问的。?·此变量的类型是 Student ,查询变量的类型是兼容的 IEnumerable 。
《心理素质训练》(PPT_85) 来自淘豆网www.taodocs.com转载请标明出处.