C
C#3mo ago
eid

yield return in c#

i can't understand yield return , i wish hear from u what do u say about it.
4 Replies
TheBoxyBear
TheBoxyBear3mo ago
Using yield with a compatible return type converts the method to an iterator returning individual items of a collection. Rather than executing the entire method right away and returning the value as defined by the return type, the actual method returns immediately, generating an object storing the state of the method body that you defined. That body only runs when MoveNext is called, executing until the next yield then pausing, exiting MoveNext with the yielded item or having MoveNext return false if `yield break or the end of the method is reached.
eid
eid3mo ago
does the iterator that yield return made it..is different from other iterators?
Mkp
Mkp3mo ago
In other words if you have an sorted list by a complex index, that is where the reference or native value wont suffice, then you have yield so you can do those mafs It also helps to hide caching behind it, in like a lazy loader (reader)
Want results from more Discord servers?
Add your server