I have some code that downloads data into a class for storage and then creates a copy of that class to pass into a method that alters the data. Somehow my original class is also being altered and I'm not sure what I'm doing wrong.
Calculations calc = new Calculations(Symbol, Market);
calc.stockData = loadData(Symbol, Market);
for (int j = calc.stockData.Count - 8; j >= 0; j--)
{
highPrice = 0;
// 0 newest
// as you go higher in the index, it is older
for (int k = j + 1; k < j + 8; k++)
{
kIndex = k;
jIndex = j;
decimal highRiskCurrentHigh = Calculations.calculateReturnPercentageStatic(calc.stockData.ElementAtOrDefault(k).Close,
calc.stockData.ElementAtOrDefault(j).High);
if (highRiskCurrentHigh > highPrice)
{
highPrice = highRiskCurrentHigh;
highIndex = k;
}
}
Test test = new Test();
test.returnPct = highPrice;
test.date = calc.stockData.ElementAtOrDefault(highIndex).Date;
test.symbolClass = symbolsList.ElementAtOrDefault(i);
Calculations copy = calc;
test.ratingClass = performCalculations(test.symbolClass, copy, test.date); // passing a copy into the method for altering
stuffList.Add(test); // inserted a breakpoint here and the original class (calc) has been altered
}