LINQ 查询条件能不能指定字段在某个集合中取值?

ltolll ltolll 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
using System;
using System.Collections.Generic;
using System.Linq;

public class Test
{

public class student
{
public int id{get;set;}
public string name{get;set;}
}

public static void Main()
{
List<student> aList = new List<student>(){
new student{id = 1,name = "s1"},
new student{id = 2,name = "s2"},
new student{id = 3,name = "s3"}
};

List<student> bList = new List<student>(){
new student{id = 2},
new student{id = 2},
new student{id = 3}
};
var cList = (from c in bList select c.id).Distinct();
foreach(var s in cList)
{
Console.WriteLine(s);
}
}
}

现在能去除bList 中的id重复项,
输出为
2
3
拉下来能不能用LINQ实现, 指定aList.id在cList取值得到集合为
2 S2
3 S3
...全文

相关推荐

评论 6
收藏 已收藏
分享
返回顶部
ltolll
C# 111,128 成员 642,536 内容