You are viewing a single comment's thread from:
RE: What the hell does C# yield do?
yield, for me, is one of those Python functionalities I usually avoid because I know roughly what it does but if I really want to use it I'll have to read up the documentation on it again - to make sure I don't introduce bugs.
Yep, it gets complex. The key to it is that you avoid mutation of any state and there is 0 risk. If you have mutation then the problem is you have no idea when code will run and hence when the mutation will take place.
In C# you can force evaluation early
var oldPeople = people.Where(persion => person.Age >= 65).ToArray();
The ToArray() forces all the code to execute there and then, removes the lazy state