-1

Take a look for example at the accepted answer here Which method performs better: .Any() vs .Count() > 0?. Now I wonder if LINQ functions (e.g. Last, FirstOrDefault) are completely naive and all they do is enumerating/checking IEnumerable or they check what data structure is beneath (at least for basic collections like Array, List) and the execution is optimized for such structures?

Community
  • 1
  • 1
greenoldman
  • 16,144
  • 25
  • 114
  • 178

1 Answers1

1

They do where it makes sense, typically not for the actual type but for an interface (for example they check for IList when it helps speedup)

Ronan Thibaudau
  • 3,158
  • 3
  • 29
  • 74