What is the difference between First() and Take(1)?

Technology CommunityCategory: LINQWhat is the difference between First() and Take(1)?
VietMX Staff asked 3 years ago
Problem

Consider:

var result = List.Where(x => x == "foo").First();
var result = List.Where(x => x == "foo").Take(1);

The difference between First() and Take() is that First() returns the element itself, while Take() returns a sequence of elements that contains exactly one element. (If you pass 1 as the parameter).