> Well, I found the problem... still strange...
> I add an item to the cache.
[quoted text clipped - 32 lines]
> >
> > http://www.yoda.arachsys.com/csharp/complete.html
Hi,
It's an arraylist with my own objects (classes).
So, it sounds like you know why...
Thanks,
Arjen
> What type is the variable?
>
[quoted text clipped - 38 lines]
> > >
> > > http://www.yoda.arachsys.com/csharp/complete.html
Bruce Wood - 30 Aug 2006 17:25 GMT
It's because what is cached is a _reference_ to the object instance.
Class instance are _reference types_, so your local variable and the
cache both store the same thing: a reference (or, if you prefer, a
pointer) to the same object in memory. Change the state (contents) of
the object, and it changes in both places because there is only one
object.
If you want to cache a copy of the object, not a reference to the same
object you're holding, then your class has to implement ICloneable and
you have to cache myObject.Clone(), not myObject.
> Hi,
>
[quoted text clipped - 46 lines]
> > > >
> > > > http://www.yoda.arachsys.com/csharp/complete.html