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
- 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.