foreach(DataRow ㅡ speed improvment

patrick

Well-known member
Joined
Dec 5, 2021
Messages
302
Programming Experience
1-3
There are 124769 DataRow.


The code for statement blow is too slow.
C#:
var selectedRows = 124769 DataRows;
string str;
foreach (DataRow selectedRow in selectedrows)
{
str += ";" ;
str += selected[LOT_ID].Tostring();
}
 
Last edited by a moderator:
It's not the foreach that is slow. It is your use of string concatenation that is slow because each += allocates a brand new string and needs to copy the old characters into the new string. Use a StringBuilder instead.
 
It's not the foreach that is slow. It is your use of string concatenation that is slow because each += allocates a brand new string and needs to copy the old characters into the new string. Use a StringBuilder instead.
thank you so much.

you are my teacher
 
Back
Top Bottom