我们必须将一个数据表转换为另一个数据表,这主要涉及将源数据表转换为不同的格式。按顺序考虑,我将其实现如下:
DataTable riskTable;
this.InitializeRmmRiskTable(out riskTable); // Initializes the columns
var calculatedRisk = (from DataRow tradeRow in tradeTableToFilter.Rows
where tradeRow["TradeID"] != null
select new
{
ROW_ID = 0,
TCN = tradeRow["TradeID"].ToString(),
CCY = tradeRow["CURRENCY"],
USD_VALUE = calculator.Invoke(tradeRow) // configured delegate that will fetch the value
}).Distinct();
foreach (var rowData in calculatedRisk)
{
DataRow rowToAdd = riskTable.NewRow();
rowToAdd["ROW_ID"] = rowData.ROW_ID;
rowToAdd["TCN"] = rowData.TCN;
rowToAdd["CCY"] = rowData.CCY;
rowToAdd["USD_VALUE"] = rowData.USD_VALUE;
riskTable.Rows.Add(rowToAdd);
}
return riskTable;
有什么建议可以在内存占用和执行周期方面进行优化吗?