首页 > 其他 > 详细

Linq联接

时间:2015-09-14 20:57:21      阅读:176      评论:0      收藏:0      [点我收藏+]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Linq联接
{
    class Program
    {
        public class Student 
        {
            public int stID;
            public string LastName;
        }
        public class CourseStudent
        {
            public string CourseName;
            public int stID;
        }
        static Student[] students = new Student[] { 
                    new Student { stID = 1, LastName = "Carson" } ,
                    new Student { stID = 2, LastName = "Jack" }, 
                    new Student { stID = 3, LastName = "Tom" } 
                     };
        static CourseStudent[] courseStudents = new CourseStudent[]{
        new CourseStudent{CourseName="asd",stID=1},
        new CourseStudent{CourseName="asd",stID=2},
        new CourseStudent{CourseName="sfh",stID=1},
        new CourseStudent{CourseName="dgfsd",stID=2},
        new CourseStudent{CourseName="dgfsd",stID=3},
        };
        static void Main(string[] args)
        {
            var query = from s in students          //s和c是迭代器
                        join c in courseStudents
                        on s.stID equals c.stID
                        where c.CourseName == "asd"
                        select s.LastName;
            foreach (var q in query)
                Console.WriteLine("Student Taking asd :{0}",q);
            Console.ReadKey();
        }
    }
}

Linq联接

原文:http://www.cnblogs.com/sulong/p/4808051.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!