linq - C# laziness question -


what's common approach design applications, rely on lazy evaluation in c# (linq, ienumerable, iqueryable, ...)?

right attempt make every query lazy possible, using yield return , linq queries, in runtime lead "too lazy" behavior, when every query gets builts it's beginning resulting in severe visual performance degradation.

what means putting tolist() projection operators somewhere cache data, suspect approach might incorrect.

what's appropriate / common ways design sort of applications beginning?

i find useful classify each ienumerable 1 of 3 categories.

  1. fast ones - e.g. lists , arrays
  2. slow ones - e.g. database queries or heavy calculations
  3. non-deterministic ones - e.g. list.select(x => new { ... })

for category 1, tend keep concrete type when appropriate, arrays or ilist etc. category 3, best keep local within method, avoid hard-to find bugs. have category 2, , when optimizing performance, measure first find bottlenecks.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -