Collections Flashcards

1
Q

What is yield used for in C#?

A

You use a yield return statement to return each element one at a time. The sequence returned from an iterator method can be consumed by using a foreach statement or LINQ query. Each iteration of the foreach loop calls the iterator method.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the difference between yield and return in C#?

A

The only difference between yield and return is whenever a yield statement is encountered in a function, the execution of the function is suspended and a value is sent back to the caller, but because of the yield whenever the function is called again, the execution of the function begins where it left off previously.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly