在查询表达式中使用方法语法

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Linq_1
{
    
class Program
    {
        
static void Main(string[] args)
        {
            var studentQuery6 
=
     from student 
in students
     let totalScore 
= student.Scores[0+ student.Scores[1+
         student.Scores[
2+ student.Scores[3]
     select totalScore;

            
double averageScore = studentQuery6.Average();
            Console.WriteLine(
"Class average score = {0}", averageScore);
        }

        
static List<Student> students = new List<Student>
{
   
new Student {First="Svetlana", Last="Omelchenko", ID=111, Scores= new List<int> {97928160}},//
   new Student {First="Claire", Last="O’Donnell", ID=112, Scores= new List<int> {75849139}},
   
new Student {First="Sven", Last="Mortensen", ID=113, Scores= new List<int> {88946591}},
   
new Student {First="Cesar", Last="Garcia", ID=114, Scores= new List<int> {97898582}},
   
new Student {First="Debra", Last="Garcia", ID=115, Scores= new List<int> {35729170}},
   
new Student {First="Fadi", Last="Fakhouri", ID=116, Scores= new List<int> {99869094}},
   
new Student {First="Hanying", Last="Feng", ID=117, Scores= new List<int> {93928087}},
   
new Student {First="Hugo", Last="Garcia", ID=118, Scores= new List<int> {92908378}},//
   new Student {First="Lance", Last="Tucker", ID=119, Scores= new List<int> {68798892}},
   
new Student {First="Terry", Last="Adams", ID=120, Scores= new List<int> {99828179}},//
   new Student {First="Eugene", Last="Zabokritski", ID=121, Scores= new List<int> {96859160}},//
   new Student {First="Michael", Last="Tucker", ID=122, Scores= new List<int> {94929191} }
};
    }
    
/// <summary>
    
/// 学生类
    
/// </summary>
    public class Student
    {
        
public string First { getset; }//
        public string Last { getset; }//
        public int ID { getset; }//编号
        public List<int> Scores;//分数
    }


}
posted @ 2011-05-06 14:34  袁雷  阅读(165)  评论(0编辑  收藏  举报