Friday, August 22, 2014

Why I love yield return

Aside from it's memory efficient as compared to eagerly populating list: saves us a lot of boilerplate codes too, there was once in C#'s life that there's no yield return magic yet, we have to contend with iterator design pattern, and that entails a lot of boilerplates code:

Long and short of why yield return is so awesome:

Use yield return when returning IValidatableObect, or any list for that matter. There's no need to create a List<ValidationResult>

No comments:

Post a Comment