Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用linq从2个不同的对象中进行选择_C#_Linq_Select - Fatal编程技术网

C# 使用linq从2个不同的对象中进行选择

C# 使用linq从2个不同的对象中进行选择,c#,linq,select,C#,Linq,Select,我想从Linq中的两个不同对象中进行选择,以便比较它们。这就是我试过的 var myItem = (from abc in firstList.Value from cds in secondList where (abc.Key.theKey == cds.secondList.theSecondKey select cds).SingleOrDefault(); 虽然我得到了一个错误: 调用“SelectM

我想从Linq中的两个不同对象中进行选择,以便比较它们。这就是我试过的

var myItem = (from abc in firstList.Value
              from cds in secondList
              where (abc.Key.theKey == cds.secondList.theSecondKey
              select cds).SingleOrDefault();
虽然我得到了一个错误:

调用“SelectMany”时类型推断失败

如果这是您的确切查询,可能是因为您的括号不匹配。试试这个:

var myItem = (from abc in firstList.Value
              from cds in secondList
              where abc.Key.theKey == cds.secondList.theSecondKey
              select cds).SingleOrDefault();
诚然,我可能会重写使用连接的说法——在大多数情况下,连接会更有效


但是,如果这不是您的确切查询,请发布一个简短但完整的程序来演示问题。不清楚为什么
cds
会有一个
secondList
属性。一个完整的例子演示了这个问题,这会使问题变得简单得多。

你有一个更详细的开场白:

var myItem = (from abc in firstList.Value
              from cds in secondList
              where abc.Key.theKey == cds.secondList.theSecondKey
              select cds
             ).SingleOrDefault();

您需要显示所选对象的结构。第一个列表是Dictionary,第二个是ClassD的列表。。它足够好吗?告诉我们你想用你的收藏品实现什么。我无法从你的查询中理解一件事,因为它离工作查询很远。您是否正在尝试根据第一个列表中的项目为第二个列表选择项目?该代码短于结束括号。。。