Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

what is yield keyword in .Net?

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


Please Help Members By Posting Answers For Below Questions

What is the difference between override and overload in a method?

1285


What is a garbage collector?

1192


Explain the top .net class that everything is derived from?

1111


Is .net core free?

1146


Please explain when should you use .net web forms over asp.net mvc?

1055


Do you know what are three common acronyms used in .net, and what do they stand for?

1070


Explain why do we use msmq?

1063


Should I implement finalize on my class? Should I implement idisposable?

1071


What is .net3.0 and .net3.5?

1038


Explain how to rename a table using sql queries?

1132


Does .net supports destructors concept?

2111


Is .net core stable?

984


What is a formatter in .net?

1070


Explain .NET architecture?

1191


Do you know the difference between the stack and the heap?

1056