W3
Teacher
Explore
Browse by field
Artificial Intelligence
Accounting & Finance
Information Technology
Show all fields
Interview Q&A
All Interview Questions
Beginner
Intermediate
Advanced
Practice
MCQs
Quizzes
Mock Interviews
About
Light
Dark
Auto
Sign in
Get Started
Search interview questions
Search
21 questions for “Iterators & yield return”
Found in 1 field. Select a question to see its full answer.
Matching topics
C#
Iterators
&
yield
return
10
JavaScript
Iterators
& Generators
1
Information Technology
21 questions in 3 technologies
#
Question
Technology
Topic
Level
1
What does '
yield
return
' do inside a method, and how does it turn an ordinary method into an iterator?
C# › Iterators & yield return
C#
Iterators
&
yield
return
Beginner
2
Why is a method using '
yield
return
' considered LAZY, and what does that mean for when its code actually executes?
C# › Iterators & yield return
C#
Iterators
&
yield
return
Beginner
3
How would you implement a custom IEnumerable<T> on your own class using
yield
return
, letting it support foreach?
C# › Iterators & yield return
C#
Iterators
&
yield
return
Intermediate
4
How does '
yield
break' work, and how does it differ from a plain '
return
' statement inside a regular method?
C# › Iterators & yield return
C#
Iterators
&
yield
return
Intermediate
5
How would you implement a custom lazy 'Where' and 'Select' from scratch using
yield
return
, mirroring how LINQ actually works internally?
C# › Iterators & yield return
C#
Iterators
&
yield
return
Advanced
6
How would you implement infinite lazy sequence generation using
yield
return
, and why is this safe despite never 'finishing'?
C# › Iterators & yield return
C#
Iterators
&
yield
return
Advanced
7
How would you combine
yield
return
with async/await to build an IAsyncEnumerable<T>-producing async iterator method?
C# › Iterators & yield return
C#
Iterators
&
yield
return
Advanced
8
How 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 return
C#
Iterators
&
yield
return
Intermediate
9
How does the compiler-generated state machine for an iterator method actually work internally, and what class does it implement?
C# › Iterators & yield return
C#
Iterators
&
yield
return
Advanced
10
How 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 return
C#
Iterators
&
yield
return
Advanced
Show all 21 questions in Information Technology