我有执行此操作的 C# 代码:
// This returns 10,000 rows quite quickly, but displaying them below is slow
DataTable dt = GetUsageStats();
string html = "<table>";
// This part is really slow
foreach (DataRow dr in dt.Rows)
{
html += "<tr>";
html += "<td>" + dr["column1"].ToString() + "</td>";
html += "<td>" + dr["column2"].ToString() + "</td>";
...
html += "<td>" + dr["column5"].ToString() + "</td>";
html += "</tr>";
}
html += "</table>";
由于有 10,000 条左右的记录,foreach 变得如此缓慢。有什么机制可以加快这个过程吗?
谢谢!