Answer Posted / banaja
public class ExampleIterator : IEnumerable {
public IEnumerator GetEnumerator() {
yield return 1;
}
}
The class ExampleIterator implements the IEnumerable
interface, which requires the GetEnumerator method to be
implemented. The GetEnumerator method returns an
IEnumerator instance. In the implementation of
GetEnumerator, the value 1 is returned rather than an
IEnumerator interface instance. This is odd, because how
can a value type be returned when a reference type is
expected? The magic is the yield keyword, which provides
the missing code in the form of generated IL.
The yield keyword is a compiler directive that generates a
very large chunk of IL code. Using ILDASM.exe it is
possible to reverse engineer what the compiler generated
| Is This Answer Correct ? | 3 Yes | 0 No |
Post New Answer View All Answers
What is the difference between override and overload in a method?
What is a garbage collector?
Explain the top .net class that everything is derived from?
Is .net core free?
Please explain when should you use .net web forms over asp.net mvc?
Do you know what are three common acronyms used in .net, and what do they stand for?
Explain why do we use msmq?
Should I implement finalize on my class? Should I implement idisposable?
What is .net3.0 and .net3.5?
Explain how to rename a table using sql queries?
Does .net supports destructors concept?
Is .net core stable?
What is a formatter in .net?
Explain .NET architecture?
Do you know the difference between the stack and the heap?