Log in from a computer to take this course

You'll need to log in from a computer to start Learn C#. But you can practice or keep up your coding streak with the Codecademy Go app. Download the app to get started.

apple storegoogle store
Learn

In LINQ, you can write queries in two ways: in query syntax and method syntax.

Query syntax looks like a multi-line sentence. If you’ve used SQL, you might see some similarities:

var longLoudHeroes = from h in heroes where h.Length > 6 select h.ToUpper();

Method syntax looks like plain old C#. We make method calls on the collection we are querying:

var longHeroes = heroes.Where(h => h.Length > 6); var longLoudHeroes = longHeroes.Select(h => h.ToUpper());

In LINQ, we see where/Where() and select/Select() show up as both keywords and method calls. To cover both cases, they’re generally called operators.

Every developer has a personal preference between syntaxes, but you should be able to read both. In this lesson we’ll start with query syntax then move on to method.

Instructions

1.

Read the two queries in Program.cs. Each one returns a sequence of phrases, one for each hero name that contains an ‘a’. Run the code to see the output.

The queries return the same output, but they are written with different syntax. Which seems easier to read to you?

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?