C#基础(004)---泛型与数组2

C#基础---泛型与数组2

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

namespace ConsoleApplication1
{
    class Program
    {
       
        public class Student
            //学生类作数据源
        {   
            public string Name
            {
                get;
                set;
            }  
            public List<int> Scores
            {
                get;
                set;
            } 
            //成绩集合
        }
        static void Main(string[] args)
        {   
            //初始化泛型类 List<Student>集合元素包含成绩内部序列 List<int>   
            List<Student> students = new List<Student>();
            students.Add(new Student { Name = "张三",Scores = new List<int> { 93, 72, 88, 78 } });
            students.Add(new Student { Name = "李四", Scores = new List<int> { 95, 71, 88, 68 } }); 

     students.Add(new Student { Name = "王五", Scores = new List<int> { 65, 71, 88, 68 } });     
            //使用Linq查询   
            var Query = from student in students
                        where student.Scores.Average() >= 80
                        select new   
                        {                  
                            姓名 = student.Name, 
                            成绩 = student.Scores.Average()   
                        };  
            foreach (var q in Query) 
                Console.WriteLine("{0}  {1}", q.姓名, q.成绩);
            Console.ReadLine();
        }
       
    }

}

输出:

posted on 2014-04-18 00:21  lbsf  阅读(101)  评论(0)    收藏  举报

导航