使用英语阅读

通过


编译器错误 CS0745

应为上下文关键字 "by"

group 子句的模式是 group...by 跟一个可选 into,如以下示例所示:

string[] names = { "Bob", "Bill", "Jonetta", "Mary" };  
  
var query = from name in names  
            group name by name[0];  

var query2 = from name in names  
             group name by name[0] into g  
             //...additional query clauses  

更正此错误

  1. by 关键字添加到 group 子句中。

示例

以下代码生成 CS0745:

// cs0745.cs  
using System;  
using System.Linq;  
  
public class C  
{  
    public static int Main()  
    {  
        string[] names = { "Bob", "Bill", "Jonetta", "Mary" };  
  
        var query = from name in names  
                    group name name[0]; // CS0745  
  
        return 1;  
    }  
}  

请参阅