.net - Does a method that returns a collection get called in every iteration in a foreach statement in C#? -
I was working with some C # code this morning and I had something like this:
Therefore, as I do not have a complete understanding of the language structure, I would like to know whether GetDataTable () is called for recurrence every time or it is called only once and the resulting data (which are rows) in the memory loop Is saved by Dyam. In any case, I declared a new collection to save it and worked from there ...
I added a new variable so I did this:
DataRowCollection rowCollection = MyMethod .GetDataTable () Rows Thanks in advance.
Thanks in advance.
/ div>
Do not worry about it; It only executes GetDataTable () internally to obtain the calculator object from DataRowCollection, and then after each part gets from each item through the loop.
Comments
Post a Comment