Share via

LINQ causes errors

Sergio23 271 Reputation points
2021-07-08T05:46:52.26+00:00

LINQ gives me errors and I use examples from the microsoft site

Link: https://learn.microsoft.com/it-it/dotnet/csharp/linq/write-linq-queries
Example
using System;
using System.Collections;

namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
// Query #1.
List<int> numbers = new List<int>() { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };

        // The query variable can also be implicitly typed by using var  
        IEnumerable<int> filteringQuery =  
            from num in numbers  
            where num < 3 || num > 7  
            select num;  

        // Query #2.  
        IEnumerable<int> orderingQuery =  
            from num in numbers  
            where num < 3 || num > 7  
            orderby num ascending  
            select num;  

        // Query #3.  
        string[] groupingQuery = { "carrots", "cabbage", "broccoli", "beans", "barley" };  
        IEnumerable<IGrouping<char, string>> queryFoodGroups =  
            from item in groupingQuery  
            group item by item[0];  
    }  
}  

}

Thanks

Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.

0 comments No comments

Answer accepted by question author

Sergio23 271 Reputation points
2021-07-08T06:16:13.257+00:00

Sorry, but I found the error were caused by the missing reference to
using System.Linq;
using System.Collections.Generic;

Was this answer helpful?

0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.