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?

Answers were Sorted based on User's Feedback



what is yield keyword in .Net?..

Answer / 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

what is yield keyword in .Net?..

Answer / puneet meena

while(get_next_record_from_database)
{ yield return your_next_record;}

It allows you to quickly create an object collection (an Enumerator) that you can loop through and retrieve records. The yield return statement handles all the of the code needed to create an enumerator for you.

The big part of the yield return statement is that you don't have to load all the of the items in a collection before returning the collection to the calling method. It allows lazy loading of the collection, so you don't pay the access penalty all at once.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Dot Net General Interview Questions

How to load the contents of an xml file into an xmldocument object?

0 Answers  


What is the managed and unmanaged code in .net?

2 Answers  


Which among the following two is best and why? Abstract Class and Interface. What is the major difference in between those two except the discrete methods and methods with function definition.

4 Answers   247Customer,


I am constantly writing the drawing procedures with system.drawing.graphics, but having to use the try and dispose blocks is too time-consuming with graphicsobjects. Can I automate this?

0 Answers  


Differentiate between managed and unmanaged code?

0 Answers  


How to manage pagination in a page using .net?

0 Answers  


Explain what is the difference between a class and an object, and how do these terms relate to each other?

0 Answers  


What are situations when you register .NET assembly in GAC ?

0 Answers   UGC Corporation,


What is garbage collection and how it works. Provide a code example of how you can enforce garbage collection in .net?

0 Answers  


What is the benefit of .net core?

0 Answers  


If I am writing in a language like vb or c++, what are the procedures to be followed to support .net?

0 Answers  


how can i create a table from front end to back end in wabe page?

0 Answers  


Categories