Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.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同时查询两个集合_C#_.net_Linq_Collections - Fatal编程技术网

C# 使用Linq同时查询两个集合

C# 使用Linq同时查询两个集合,c#,.net,linq,collections,C#,.net,Linq,Collections,如果我有两个对象集合,是否可以在一个查询中有效地联接它们并从两个对象中进行选择 例如: var collection1 = GetSomeData(); var collection2 = GetSomeMoreData(); var myResult = from x in collection1 from y in collection2 where x.SomeProperty = "Yes" wh

如果我有两个对象集合,是否可以在一个查询中有效地联接它们并从两个对象中进行选择

例如:

var collection1 = GetSomeData();
var collection2 = GetSomeMoreData();

var myResult = from x in collection1
               from y in collection2
               where x.SomeProperty = "Yes"
               where y.SomeProperty = "Yes"
               select x, select y;
GetSomeData
GetSomeMoreData
都返回
IEnumerable

显然,这并没有编译。。。但希望它能说明我的想法……

我想你想要:

或在查询语法中:

var myResult = from x in collection1.Concat(collection2)
               where x.SomeProperty == "Yes"
               select x;

请注意,在LINQ上下文中,您使用的“join”一词通常指基于某个键在两个序列之间查找(并配对/分组)公共元素。这不是你想要做的,是吗?

我的结果应该包含什么?也许可以加个例子?谢谢。。。我应该想到string.concat;-)“加入”这个术语使我感到很不自在
var myResult = from x in collection1.Concat(collection2)
               where x.SomeProperty == "Yes"
               select x;