Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.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#_Linq - Fatal编程技术网

C# LINQ复合选择问题

C# LINQ复合选择问题,c#,linq,C#,Linq,我在编译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}; int[]numbersA={0,2,4,5,6,8,9}; int[]number

我在编译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};
int[]numbersA={0,2,4,5,6,8,9};
int[]numbersB={1,3,5,7,8};
变量对=
从一个数字中,
b在数字b中
其中a
代码来自此处的教程,标题为“SelectMany-Compound from 1”:

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

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

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

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

var pairs = from a in numbersA
            from b in numbersB
            where a < b
            select new {a, b};
var pairs=来自数字中的a
从数字b中的b开始
其中a
如果我正确理解您的意图,那么您需要另一个

像这样:

var pairs =
    from a in numbersA // Comma removed from end of line here
    from b in numbersB // additional "from" keyword at start of line
    where a < b
    select new {a, b};
var对=
从一个in numbersA//逗号从这里的行尾删除
从编号b中的b开始//行开头的附加“from”关键字
其中a
使用等效的流利语法,仅供记录:

var pair = numbersA.SelectMany(a => numbersB, (a, b) => new {a, b})
                   .Where(n => n.a < n.b);
var pair=numbersA.SelectMany(a=>numbersB,(a,b)=>new{a,b})
.式中(n=>n.a
你先到:)我投票支持你。谢谢,我试过了,效果很好。遗憾的是,MS站点的代码无效!那很有效,谢谢!不过很抱歉,mehrdad先回答了我的问题谢谢你准确地问了我这一分钟要问的问题:)