serialization on static values

D

Deleo

Hello
Im having trouble serializing a static value inside an object and
deserialize it correctly.
Heres how it works

The idea is that i make lots of objects that has unique IDs, but each object
share one value and that is the ID of the last object created. This way i
know what the ID of the next object will be. So lets say 10 objects share
one value (static).
I create 10 objects and the static variable= 10. on all thos objects...

Now i serialize these objects inside a List<T>.
And close the application. Then i start the application and load in the
objects i serilized, but the problem is that the static value is reset, its
= 0....

That means that the static value did not serialize like the rest of the
objects.
How can i fix this? that my Shared value is saved.

When i load the 10 objects i want that share variable to be 10 and not 0.

thank you.
 
P

Pete Davis

Remember, serialization is serializing instances of the objects. Static data
is not serialized because it's not instance data and there's really no way
to "automatically" do it.

Either store the count somewhere or after you load all the objects, set the
value to the highest ID.

Pete
 
D

Deleo

ok thanks
Ill work around it then....
just wanted to know if I could serialize the thing :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top