And the difference between FirstOrDefault (func) & Where (func) .FirstOrDefault ()?

Is there any difference between

DataFeedManager.LoadAllDataFeeds().FirstOrDefault(d => d.ItemID == itemId); 

and

 DataFeedManager.LoadAllDataFeeds().Where(d=>d.ItemID = itemId).FirstOrDefault(); 

Is there any special reason to prefer each other?

+2
linq
source share
1 answer

Prefer the first for brevity, if you are comfortable with it.

Prefer the latter for clarity if you are not familiar with the various overloads available.

(Where the "you" is actually "everyone is working on the code," of course.)

+5
source share

All Articles