【发布时间】:2011-08-03 19:16:28
【问题描述】:
考虑这些代码行:
//prodProdGroup is a list within the itm object that I need to search. The items
//within the list are of type ProductionCostCalcHelper. I need to find one
//of the ProductionCostCalcHelper records in the list, calculate its total dollar value
//and assign it the value
ProductionCostCalcHelper prodGroupItm = itm.prodProdGroup.SingleOrDefault(f => f.MAST_PROJ.Trim() == laborItm.MAST_PROJ.Trim());
ProductionCostCalcHelper prodGroupItm2 = itm.prodProdGroup.SingleOrDefault(f => f.MAST_PROJ.Trim() == laborItm.MAST_PROJ.Trim());
if (prodGroupItm != null)
{
prodGroupItm.TOTAL_DOLLAR = avgDollarsPerHour * prodGroupItm.HOURS;
}
我假设 SingleOrDefault 方法会通过引用返回对象,但事实并非如此。在更改了 ProdGroupItm 的 TOTAL_DOLLAR 金额后,ProdGroupItm2 保持不变,证明它们没有引用列表中的内容。为什么是这样?有没有办法更新列表中对象的值?
【问题讨论】:
-
ProductionCostCalcHelper是一个结构吗?