LINQ 查询条件能不能指定字段在某个集合中取值?
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
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
...全文
相关推荐
.net linq动态组合查询条件及排序
本文将深入探讨如何在.NET中利用LINQ实现动态组合查询条件及排序。首先,让我们了解什么是LINQ。
Linq动态查询、行转列
在传统的LINQ查询中,我们通常使用lambda表达式或方法链来定义查询条件。然而,在某些场景下,查询条件可能在运行时才确定,这就是动态LINQ发挥作用的地方。
linq查询整个的简单方法
在C#中,LINQ提供了一种一致的查询接口,使代码更加简洁和可读。在提供的代码片段中,我们看到如何使用LINQ查询一个名为`FunctionPoint`的表或集合。
linq 查询 Linq 高级查询实例代码
在实例代码的LINQ查询部分,首先通过Regex.Matches方法找到所有符合条件的匹配项,然后通过Select方法处理这些匹配项,将匹配到的城市名称和区号转换成字典的键值对。
用Linq从一个集合选取几列得到一个新的集合(可改列名)
本文将深入探讨如何使用Linq从一个集合中选取特定的列,并在创建新集合的同时进行列名的修改。首先,让我们了解基本的Linq查询语法。


