DataTable.SetField出现缓慢

时间:2018-10-18 15:02:15

标签: c# datatable

从性能分析来看,这非常慢:

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行。谁能建议一种更快的方法?

0 个答案:

没有答案