从性能分析来看,这非常慢:
public static DataTable ReplaceNulls(DataTable table, double replacementValue = 0)
{
int r = -1;
foreach (DataRow row in table.Rows)
{
r++;
foreach (DataColumn col in table.Columns.Cast<DataColumn>().Skip(1))
{
if ((object)row[col] == DBNull.Value)
{
row.SetField(col, replacementValue);
}
}
}
return table;
}
问题是SetField行。谁能建议一种更快的方法?