So far you’ve seen query syntax and two flavors of method syntax.

// Query syntax var longLoudheroes = from h in heroes where h.Length > 6 select h.ToUpper(); // Method syntax - separate statements var longHeroes = heroes.Where(h => h.Length > 6); var longLoudHeroes = longHeroes.Select(h => h.ToUpper()); // Method syntax - chained expressions var longLoudHeroes2 = heroes .Where(h => h.Length > 6) .Select(h => h.ToUpper());

As you get into more advanced LINQ queries and learn new operators, you’ll get a feel for what works best in each situation. For now, we generally follow these rules:

  1. For single operator queries, use method syntax.
  2. For everything else, use query syntax.



Write a method-syntax query that transforms each element in heroes to this format:

Introducing...[hero's name]!

Write a query-syntax query that selects elements containing a space and returns the index of the space in each element. For example, instead of "D. Va", the result should contain 2.


Print out all of the elements of both query results to check your work.

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?