Wednesday, 9 May 2018
c# - What is yield and what is the benefit to use yield in asp .NET?
Answer
Answer
Can you help me in understanding of yield
keyword in asp .NET(C#)
.
Answer
Yield return automatically creates an enumerator for you.
http://msdn.microsoft.com/en-us/library/9k7k7cf0.aspx
So you can do something like
//pseudo code:
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.
When to use Yield Return.
casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV
In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...
-
The whole error output being: LNK2019 unresolved external symbol wWinMain referenced in function "int __cdecl __scrt_common_main_seh(vo...
-
I have come across CORS issues multiple times and can usually fix it but I want to really understand by seeing this from a MEAN stack paradi...
-
I recently used canvas to conert images to webp, using : const dataUrl = canvas.toDataURL('image/webp'); But this takes a lots of ti...
No comments:
Post a Comment