Learn
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;
Instructions
1.
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?)
or
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'?
2.
Fix the errors by adding references to both the System.Collections.Generic
and System.Linq
namespaces.
Take this course for free
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.