zoukankan      html  css  js  c++  java
  • Group Join 操作

    GroupJoin

    The GroupJoin operator performs the same task as Join operator except that GroupJoin returns a result in group based on specified group key.
    The GroupJoin operator joins two sequences based on key and groups the result by matching key and then returns the collection of grouped result and key.

    Example

    public class Student {
    	public int StudentID {get;set;}
    	public string StudentName {get;set;}
    	public int StandardID {get;set;}
    }
    
    public class Standard {
    	public int StandardID{get;set;}
    	public string StandardName{get;set;}
    }
    
    IList<Student> studentList =newList<Student>(){
    	newStudent() { StudentID = 1, StudentName = "John", StandardID = 1 },
    	newStudent() { StudentID = 2, StudentName = "Moin" ,StandardID = 1 },
    	newStudent() { StudentID = 3, StudentName = "Bill" ,StandardID = 2 },
    	newStudent() { StudentID = 4, StudentName = "Ram" ,StandardID = 2 },
    	newStudent() { StudentID = 5, StudentName = "Ron" }
    };
    
    IList<Standard> standardList = newList<Standard>(){
    	newStandard() { StandardID = 1, StandardName = "Standard 1" },
    	newStandard() { StandardID = 2, StandardName = "Standard 2" },
    	newStandard() { StandardID = 3, StandardName = "Standard 3" }
    };
    
    var groupJoin = standardList.GroupJoin(studentList,//inner sequence
    	std => std.StandardID,//outerKeySelector
    	s => s.StandardID,//innerKeySelector
    	(std, studentsGroup) => new// resultSelector
    	{
    		Students = studentsGroup,
    		StandarFulldName = std.StandardName
    	});
    
    foreach(var item in groupJoin)
    {
    	Console.WriteLine(item.StandarFulldName);
    	foreach(var stud in item.Students)
    	Console.WriteLine(stud.StudentName);
    }
    

    Results:

    Standard1:
    John,
    Moin,
    Standard2:
    Bill,
    Ram,
    Standard3:

  • 相关阅读:
    面试汇总——说一下CSS盒模型
    各厂面试题汇总
    为网页背景添加一个跟随鼠标变幻的动态线条
    lnmp一键安装包
    java独立小程序实现AES加密和解密
    git命令note
    不可思议的纯 CSS 滚动进度条效果
    Git-Book
    CentOS搭建Git服务器及权限管理
    vim编辑器里shift + 3 出现高亮问题,怎么取消掉
  • 原文地址:https://www.cnblogs.com/wuyicqb/p/12728100.html
Copyright © 2011-2022 走看看