Reusing Object does not work properly
Posted
by balexandre
on Stack Overflow
See other posts from Stack Overflow
or by balexandre
Published on 2010-03-22T22:12:05Z
Indexed on
2010/03/22
22:21 UTC
Read the original article
Hit count: 386
Hi guys,
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
© Stack Overflow or respective owner