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

Which dll is required to translate xml to sql in internet information server (iis)?

744


Explain what is an anonymous method and how is it different from a lambda expression?

687


Explain me why do we use msmq?

759


Explain the different parts of an assembly?

768


Can you explain what do you understand about web service?

803


Explain how do assemblies find each other?

777


What is Full trust permission set in .Net

2091


What's singleton activation mode in .net?

790


Write a program to create a user control with name and surname as data members and login as method and also the code to call it.

667


Is .net front end or backend?

757


How many design patterns can be created in .net?

772


When we use windows api in .net is it managed or unmanaged code?

781


What is the benefit of .net core?

686


How do I spawn a thread?

724


Explain what are possible implementations of distributed applications in .net?

711