我传递了一个我想要UNTOUCHED的对象数组但是出于某种原因无论我尝试什么,传入的原始数组都被更改。
private DSPPositionPeriodDO[] CompactShortTermData(DSPPositionPeriodDO[] data)
{
DSPPositionPeriodDO[] resultArray = (DSPPositionPeriodDO[])data.Clone();
int? hoursToAggBy = null;
// it is short term, the data gets too much so decide how many
// hours to aggregate by.
var days = (_endDate - _startDate).TotalDays;
if (days <= 3)
hoursToAggBy = null;
else if (days > 3 && days <= 7)
hoursToAggBy = 1;
else if (days > 7 && days <= 14)
hoursToAggBy = 2;
else if (days > 14 && days <= 21)
hoursToAggBy = 3;
else if (days > 21)
hoursToAggBy = 4;
if (hoursToAggBy != null)
{
// round down hours
foreach (var posPeriod in resultArray)
{
var sl = posPeriod.StartLocal;
sl = sl.AddHours(-(sl.Hour % hoursToAggBy.Value));
sl = sl.AddMinutes(-sl.Minute);
posPeriod.StartLocal = sl;
}
// group by entity & time -- get average
var groupedData = resultArray.GroupBy(x => new
{
x.EntityId,
x.EntityCode,
x.StartLocal
})
.Select(g => new DSPPositionPeriodDO
{
EntityId = g.Key.EntityId,
EntityCode = g.Key.EntityCode,
StartLocal = g.Key.StartLocal,
Volume = g.Average(v => v.Volume),
AverageVolume = null
});
resultArray = groupedData.ToArray();
}
我试图创建一个单独的副本,如:
var x = original.ToArray() .. toList() ......克隆......
等
按original
我的意思是data
对象被传入。我希望它不会被改变。