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
Explain Creational design pattern in .NET?
Difference between value type & reference types ?
What is jit compilers?
Should I use readerwriterlock instead of monitor.enter/exit?
What is the difference between vb.net and vc#.net?
Is .net a language?
Using com component in .net?
How does the generational garbage collector in the .net clr manage object lifetime? What is non-deterministic finalization?
Is .net front end or backend?
Which namespace is require to used XML in .NET?
What are the different types of memory in .net?
What does msil do?
What is the difference between a class and an object, and how do these terms relate to each other?
What is concurrency? How will you avoid concurrency when dealing with dataset?
What are asp.net authentication providers and iis security?