Don’t return a List<T> if you only need to iterate over it. Use yield return.
This generates the next item only when the caller asks for it, meaning you can process 1 billion records without ever running out of RAM. It’s the magic behind LINQ.
Daily micro-tips for C#, SQL, performance, and scalable backend engineering.
Don’t return a List<T> if you only need to iterate over it. Use yield return.
This generates the next item only when the caller asks for it, meaning you can process 1 billion records without ever running out of RAM. It’s the magic behind LINQ.