You are viewing a single comment's thread from:

RE: What the hell does C# yield do?

in #programming7 years ago

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.

Sort:  

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

Coin Marketplace

STEEM 0.21
TRX 0.20
JST 0.035
BTC 91274.52
ETH 3158.75
USDT 1.00
SBD 3.10