gpt4 book ai didi

c# - LINQ复合选择问题

转载 作者:太空狗 更新时间:2023-10-29 22:04:22 25 4
gpt4 key购买 nike

我在编译 LINQ 复合选择时遇到问题。这是代码:

int[] numbersA = { 0, 2, 4, 5, 6, 8, 9 };
int[] numbersB = { 1, 3, 5, 7, 8 };

var pairs =
from a in numbersA,
b in numbersB
where a < b
select new {a, b};

代码来自此处的教程,标题为“SelectMany - Compound from 1”:

http://msdn.microsoft.com/en-us/vcsharp/aa336758.aspx#SelectSimple1

我得到的编译时错误如下:

查询主体必须以 select 子句或 group 子句结尾

'numbersA' 之后的逗号是错误发生的地方。现在我不知道我做错了什么,因为这只是 MS 网站上的代码。任何帮助都会非常感谢。

最佳答案

您的代码不是有效的 LINQ 表达式。 from 子句仅支持单个集合。您应该重复整个 from 子句。你可能想说:

var pairs = from a in numbersA
from b in numbersB
where a < b
select new {a, b};

关于c# - LINQ复合选择问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/683995/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com