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 common type system (cts)?

994


What is alias ? Is it used in .Net ?

1111


How does the generational garbage collector in the .net clr manage object lifetime? What is non-deterministic finalization?

1004


Explain attributes in dot net?

1058


Tell us the difference between managed and unmanaged code?

1027


What is singleton activation mode in .net?

1150


What is the use of activex control in .net?

1057


What is new in .net core?

932


What is namespace in .net?

1072


What are two different types of remote object creation mode in .net?

1016


Difference abstract class and interface in .net?

1089


What is strong-typing versus weak-typing? Which is preferred?

1071


How to implement CAS in .Net?

2847


Using activex control in .net?

1015


What is dot net and its uses?

1011