6

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

What's 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 variable b is a boolean ?

Sorry about my ignorance, I am new to LINQ.

Community
  • 1
  • 1
kevin
  • 13,559
  • 30
  • 79
  • 104

1 Answers1

11

Where Filters a sequence of values based on a predicate. So in the first example you are selecting elements from your list where the function n.Id == id is true.

Select Projects each element of a sequence into a new form, so in your second example you get a list of booleans which is the result of the function n.Id == id on each element.

Sam Holder
  • 32,535
  • 13
  • 101
  • 181