1
int[] numbersA = { 0, 2, 4, 5, 6, 8, 9 };
int[] numbersB = { 1, 3, 5, 7, 8 };
var pairs =
from a in numbersA
from b in numbersB
where a < b
select new { a, b };
int[] numbersA = { 0, 2, 4, 5, 6, 8, 9 };
int[] numbersB = { 1, 3, 5, 7, 8 };
var pairs =
from a in numbersA
from b in numbersB
where a < b
select new { a, b };
你可以尝试这样的事:
var pairs = numbersA.SelectMany(a => numbersB.Where(b => b>a)
.Select(b => new { a, b }));
请参阅本.NET Fiddle
什么SelectMany
?
从将序列的每个元素投影到IEnumerable并将产生的序列展平成一个序列。
SelectMany
的结果是将包含
numbersB
阵列,其比
a
更大所有当前
a
和所有的数字之间的组合
所以,我们选择一个匿名类型具有两个属性,a
和b
。对numbersA
中的所有数字执行此操作,我们就会得到我们想要的。
https://social.msdn.microsoft.com/Forums/en-US/190e1fdf-0b38-4d30-ac52-59c8d15f771a/c-possible-lambda-in-arrays-content-declaration?forum=csharplanguage – kevintjuh93
possible [使用lambda类型的Init数组的副本](http://stackoverflow.com/questions/5368492/init-array-of-type-with-lambda) – kevintjuh93
请参阅http://codeblog.jonskeet.uk/2011/01/28/reimplementing-linq-to-objects-part-41-how-query-expressions-work /查询表达式如何翻译。 –