Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
965 views
in Technique[技术] by (71.8m points)

linq - And 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 a particular reason to prefer one over the other?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Prefer the first for brevity if you're comfortable with it.

Prefer the second for clarity if you're not as familiar with the various overloads available.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...