C# Error CS0742 – A query body must end with a select clause or a group clause

C# Error

CS0742 – A query body must end with a select clause or a group clause

Reason for the Error & Solution

A query body must end with a select clause or a group clause

A query expression must terminate with either a select clause or a group clause without a continuation.

To correct this error

  1. Add a or to the query.

Example

The following code generates CS0742:

// cs0742.cs  
using System.Linq;  
public class Test  
{  
    public static int Main()  
    {  
        int[] array = { 1, 2, 3 };  
        var query = from num in array; // CS0742  
        return 1;  
    }  
}  

If the group clause uses the keyword to store the results of the grouping into a temporary identifier, it cannot be the last clause in a query. A select or second group clause is still required.

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...