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 common type system (cts)?
What is alias ? Is it used in .Net ?
How does the generational garbage collector in the .net clr manage object lifetime? What is non-deterministic finalization?
Explain attributes in dot net?
Tell us the difference between managed and unmanaged code?
What is singleton activation mode in .net?
What is the use of activex control in .net?
What is new in .net core?
What is namespace in .net?
What are two different types of remote object creation mode in .net?
Difference abstract class and interface in .net?
What is strong-typing versus weak-typing? Which is preferred?
How to implement CAS in .Net?
Using activex control in .net?
What is dot net and its uses?