Difference between select and where in LINQ

Possible duplicate:
Linq: What is the difference between Select and Where

What is the difference between

var a = Doc.Document.Where(n => n.Id == id).SingleOrDefault(); 

and

 var b = Doc.Document.Select(n => n.Id == id).SingleOrDefault(); 

Why is variable b boolean?

Sorry for my ignorance, I'm new to LINQ.

+6
source share
1 answer

Where Filters a sequence of values โ€‹โ€‹based on a predicate. So, in the first example, you select items from your list, where the function n.Id == id is true.

Select Projects each element of the sequence into a new form, so in your second example, you get a list of logical elements that are the result of the function n.Id == id for each element.

+11
source

Source: https://habr.com/ru/post/909438/


All Articles