Skip to Content
Importing LINQ

Before we jump into the syntax and methods, let’s import the features into our code. To use LINQ in a file, add this line to the top:

using System.Linq;

Often times we use LINQ with generic collections (like lists), so you may see both namespaces imported into a file:

using System.Collections.Generic; using System.Linq;



This code is throwing errors! Run the code to see the error details.

You should have seen an error message like this:

error CS0246: The type or namespace name 'List<>' could not be found (are you missing a using directive or an assembly reference?)


error CS1935: Could not find an implementation of the query pattern for source type 'List<string>'. 'Where' not found. Are you missing a reference to 'System.Core.dll' or a using directive for 'System.Linq'?

Fix the errors by adding references to both the System.Collections.Generic and System.Linq namespaces.

Folder Icon

Take this course for free

Already have an account?