what is yield keyword in .Net?

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

What does jit compilation do in .net?

669


What is shared and repeatable inheritance?

662


What is machine.config in .net?

669


Define satelite assembly?

641


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

637






Explain how com+ related to the dna architecture?

646


Can a try block have more than one catch block?

712


Is .net core the future?

673


How does cas works?

656


What's singlecall activation mode used for in .net?

624


How does u handle this COM components developed in other programming languages in .NET?

1767


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

623


Explain the garbage collection process?

729


How to spawn a thread?

669


Interop Services?

1542