码迷,mamicode.com
首页 > 其他好文 > 详细

用Join子句进行分组联接

时间:2016-05-01 10:57:31      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:

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

namespace 用Join子句进行分组联接
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] intAry1 = { 5, 15, 25, 30, 33, 40 };
            int[] intAry2 = { 10, 20, 30, 50, 60, 70, 80 };
            var query1 = 
                from val1 in intAry1 //在数组intAry1中取到val1
                join val2 in intAry2 //同时在数组intAry2中取到val2
                on val1%5 equals val2%15 into val2Grp
                //val2Grp中的数据是val1和val2的两个对象,而不是记录
                where val2Grp.Count()!=0
                //new { VAL1 = val1, VAL2GRP = val2Grp产生一个新类型
                select (new { VAL1 = val1, VAL2GRP = val2Grp });
            //遍历新的数据类型
            foreach(var item in query1)
            {
             foreach(int item1 in item.VAL2GRP)
             {
                 Console.WriteLine(item.VAL1+" "+item1.ToString());
             }
         }
            System.Console.ReadKey();
        }
    }
}

 

用Join子句进行分组联接

标签:

原文地址:http://www.cnblogs.com/cnshuji/p/5450150.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!