Which linq method performs better: Where(expression).FirstorDefault() vs .FirstOrDefault(expression)
Introduction When it comes to LINQ, we always have multiple options to execute the query for the same scenario. Choosing correct one is always challenging aspect and debatable one. In one of our previous articles Any Vs Count , we have done performance testing about best LINQ methods over .NET types. In this article, I would like to share about Where(expression).FirstorDefault() vs .FirstOrDefault(expression) Approaches Performance testing for Where(expression).FirstorDefault() vs .FirstOrDefault(expression) is very interesting IEnumerable<T> or ICollcetion<T> .FirstOrDefault(expression) is better than Where(expression).FirstorDefault() Public API To check the performance, I need some amount of data which should already available. So I decided to choose this public api . Thanks to publicapis Public API Models Entry class using System ; using System.Collections.Generic ; using System.Text ; namespace AnyVsCount { public class Entry { pub