You’ve mostly seen LINQ used with arrays, but it can be used for lists as well! The syntax is the same:

List<string> heroesList = new List<string> { "D. Va", "Lucio", "Soldier 76" }; var longLoudheroes = from h in heroesList where h.Length > 6 select h.ToUpper(); // longLoudHeroes is [ "SOLDIER 76" ]

Technically, LINQ can be used with any type that supports foreach loops, but we won’t cover all of those here.



Query heroesList to find all hero names that contain either a . or 7 (a period or the number 7).


Store the query results in a variable of type var and use a foreach loop to print out each element.

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?