All fields

“Iterators & yield return” in Information Technology

21 questions across 3 technologies.

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
11How does yield pause and resume execution, and what does it return to the caller? JavaScript › Iterators & GeneratorsJavaScriptIterators & GeneratorsIntermediate
12How does the 'yield return'-based lazy evaluation of collections (like LINQ or a custom iterator) differ from eagerly materializing a full collection, in terms of memory usage? C# › CollectionsC#CollectionsAdvanced
13How does 'yield from' delegate iteration to a sub-generator, and what does it return as its own expression value? Python › Comprehensions & GeneratorsPythonComprehensions & GeneratorsAdvanced
14What is the difference between File.ReadAllLines() and File.ReadLines() in terms of memory usage? C# › File I/O & StreamsC#File I/O & StreamsBeginner
15What restrictions does the C# compiler enforce on Span<T> because it's a 'ref struct'? C# › Arrays, Span<T> & Memory<T>C#Arrays, Span<T> & Memory<T>Intermediate
16How does Queue<T> differ from Stack<T> in terms of the order items are removed? C# › CollectionsC#CollectionsIntermediate
17How does variable capture (closures) work in a C# lambda expression, and what pitfall occurs when capturing a loop variable? C# › Delegates, Events & LambdasC#Delegates, Events & LambdasIntermediate
18How would you use Span<T> to implement an in-place array reversal or sorting algorithm without allocating a temporary array? C# › Arrays, Span<T> & Memory<T>C#Arrays, Span<T> & Memory<T>Advanced
19How do IAsyncEnumerable<T> and 'await foreach' let you consume an asynchronous stream of values one at a time? C# › Asynchronous ProgrammingC#Asynchronous ProgrammingAdvanced
20How would you use an indexer together with a custom enumerator (implementing IEnumerable) to build a fully iterable, indexable custom collection class? C# › Indexers & Operator OverloadingC#Indexers & Operator OverloadingAdvanced
21How would you write a custom LINQ extension method that integrates seamlessly with the standard method-chaining style, like a 'DistinctBy' before it existed natively? C# › LINQC#LINQAdvanced