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

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 >  { 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 } }
};
    }
    
///   <summary>
    
///  学生类
    
///   </summary>
     public   class  Student
    {
        
public   string  First {  get set ; } //
         public   string  Last {  get set ; } //
         public   int  ID {  get set ; } // 编号
         public  List < int >  Scores; // 分数
    }


}

转载于:https://www.cnblogs.com/yuanlei347/archive/2011/05/06/2038923.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值