文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>光脚丫学LINQ(008):将多个输入联接到一个输出序列

光脚丫学LINQ(008):将多个输入联接到一个输出序列

时间:2010-10-29  来源:光脚丫思考

public class Student   
{   
    public string FirstName { get; set; }   
    public string LastName { get; set; }   
    public int ID { get; set; }   
    public string Street { get; set; }   
    public string City { get; set; }   
    public List<int> Scores;   
}   
  
public class Teacher   
{   
    public string FirstName { get; set; }   
    public string LastName { get; set; }   
    public int ID { get; set; }   
    public string City { get; set; }   
}  
public class Student
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public int ID { get; set; }
    public string Street { get; set; }
    public string City { get; set; }
    public List<int> Scores;
}

public class Teacher
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public int ID { get; set; }
    public string City { get; set; }
} 



下面的示例演示该查询:

static void Main(string[] args)   
{   
    // Create the first data source.   
    List<Student> Students = new List<Student>()   
    {   
        new Student {FirstName="Svetlana",   
            LastName="Omelchenko",    
            ID=111,    
            Street="123 Main Street",   
            City="Seattle",   
            Scores= new List<int> {97, 92, 81, 60}},   
        new Student {FirstName="Claire",   
            LastName="O’Donnell",    
            ID=112,   
            Street="124 Main Street",   
            City="Redmond",   
            Scores= new List<int> {75, 84, 91, 39}},   
        new Student {FirstName="Sven",   
            LastName="Mortensen",   
            ID=113,   
            Street="125 Main Street",   
            City="Lake City",   
            Scores= new List<int> {88, 94, 65, 91}},   
    };   
  
    // Create the second data source.   
    List<Teacher> Teachers = new List<Teacher>()   
    {                   
        new Teacher {FirstName="Ann", LastName="Beebe", ID=945, City = "Seattle"},   
        new Teacher {FirstName="Alex", LastName="Robinson", ID=956, City = "Redmond"},   
        new Teacher {FirstName="Michiyo", LastName="Sato", ID=972, City = "Tacoma"}   
    };   
  
    // Create the query.   
    var PeopleInSeattle = (from student in Students   
                           where student.City == "Seattle"  
                           select student.LastName)   
                .Concat (from teacher in Teachers   
                        where teacher.City == "Seattle"  
                        select teacher.LastName);   
  
    Console.WriteLine("The following Students and Teachers live in Seattle:");   
  
    // Execute the query.   
    foreach (var Person in PeopleInSeattle)   
    {   
        Console.WriteLine(Person);   
    }   
  
    Console.WriteLine("Press any key to exit.");   
    Console.ReadKey();   
  
}  
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载