閱讀英文

共用方式為


編譯器錯誤 CS0745

必須是內容關鍵字 'by'

group 子句的模式是後面接著選擇性 group...byinto(如下列範例所示):

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

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

更正這個錯誤

  1. 請將 by 關鍵字加入 group 子句。

範例

下列程式碼會產生 CS0745:

C#
// 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;  
    }  
}  

另請參閱