I’m reusing a created Object just to change a Date and the ordinal value, but at the end I get 6 objects exactly as the last.
in other words, I’m adding the object as a Reference and I should add as a Value
What should I inherit my Object to have the Copy() method ?
RecurringPayment rp, copy;
rp = new RecurringPayment
{
...
}
payments.Add(rp); // add first object
copy = rp; // Copy the original element
for (int i = 1; i <= 5; i++)
{
copy.NextPaymentDate = copy.NextPaymentDate.AddDays(copy.RecurringTime * 7);
copy.OrderOrdinal = copy.OrderOrdinal + 1;
payments.Add(copy); // add 5 more with X weeks ahead
}
Thank you
You can implement ICloneable and then call clone to get a shallow copy of your object!
You can implement like this if you want(there are probably better ways out there):