21 questions for “Iterators & yield return”

Found in 1 field. Select a question to see its full answer.

Information Technology

21 questions in 3 technologies

#QuestionTechnologyTopicLevel
1What does 'yield return' do inside a method, and how does it turn an ordinary method into an iterator? C# › Iterators & yield returnC#Iterators & yield returnBeginner
2Why is a method using 'yield return' considered LAZY, and what does that mean for when its code actually executes? C# › Iterators & yield returnC#Iterators & yield returnBeginner
3How would you implement a custom IEnumerable<T> on your own class using yield return, letting it support foreach? C# › Iterators & yield returnC#Iterators & yield returnIntermediate
4How does 'yield break' work, and how does it differ from a plain 'return' statement inside a regular method? C# › Iterators & yield returnC#Iterators & yield returnIntermediate
5How would you implement a custom lazy 'Where' and 'Select' from scratch using yield return, mirroring how LINQ actually works internally? C# › Iterators & yield returnC#Iterators & yield returnAdvanced
6How would you implement infinite lazy sequence generation using yield return, and why is this safe despite never 'finishing'? C# › Iterators & yield returnC#Iterators & yield returnAdvanced
7How would you combine yield return with async/await to build an IAsyncEnumerable<T>-producing async iterator method? C# › Iterators & yield returnC#Iterators & yield returnAdvanced
8How does an iterator method interact with try/finally, and when does the finally block actually execute given the method's lazy, on-demand nature? C# › Iterators & yield returnC#Iterators & yield returnIntermediate
9How does the compiler-generated state machine for an iterator method actually work internally, and what class does it implement? C# › Iterators & yield returnC#Iterators & yield returnAdvanced
10How would you write a custom iterator that safely handles resource cleanup for a lazily-enumerated database cursor, ensuring the connection is closed even if enumeration is abandoned early? C# › Iterators & yield returnC#Iterators & yield returnAdvanced