C# 用于基于另一个列表从一个列表中进行选择的linq查询 公共类测试 { int i; 字符串s; } List testList=新列表()//假设其中有一些值。 List intList=newlist(){1,2,3};

C# 用于基于另一个列表从一个列表中进行选择的linq查询 公共类测试 { int i; 字符串s; } List testList=新列表()//假设其中有一些值。 List intList=newlist(){1,2,3};,c#,linq-to-objects,C#,Linq To Objects,如何使用linq to对象从我位于intList的testList中获取项 类似于List testIntList=testList。其中(t=>intList中的t.i)从技术上讲,它应该是: public class Test { int i; string s; } List<Test> testList = new List<Test>(); //assume there are some values in it. List<int> i

如何使用linq to对象从我位于intList的testList中获取


类似于
List testIntList=testList。其中(t=>intList中的t.i)

从技术上讲,它应该是:

public class Test
{
  int i;
  string s;
}

List<Test> testList = new List<Test>(); //assume there are some values in it.

List<int> intList = new List<int>(){ 1,2,3};

这也会很有趣,并且表现良好:

HashSet<int> intList = new HashSet<int>(){ 1,2,3 };
List finalList=testList.Join(intList,
test=>test.id,
i=>i,
(t,i)=>t.ToList();

您知道何时在SQL中联接表吗
SELECT
?这是使用Linq to对象实现的方法。

我不确定自己是否理解正确。它如何知道在这个特定的查询中i=>i是什么。它没有在任何地方定义。@Alex J-表达式
i=>i
是一个lambda表达式,这是它自己的定义。在这个查询中,它表示连接使用
intList
中的值。
HashSet<int> intList = new HashSet<int>(){ 1,2,3 };
List<test> finalList = testList.Join(intList, 
                                     test => test.id,
                                     i => i,
                                     (t, i) => t).ToList();