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

This C# program calculates and displays an upper triangular matrix based on user input. Problem Statement: The program takes the...
This C# program serves as a demonstration of bitwise operators, which are fundamental operators used for manipulating individual bits in...
This C# program is designed to interchange or swap the columns of a matrix. A matrix is a two-dimensional array...