feedwall
feedwall

Reputation: 1574

Write many variables / objects of different type in the one binary file with C#

I have several objects which I would like to serialize binary in one file. For the single one object I know how to do this and I can read it correctly back also.

But this means I need for each variable another new file and I would like to store all these different objects in the same binary file. I don't know if this is possible. I use a file stream where the object is serialized to. How would a code look like which can binary serialize multiple objects of different kind in the one file?

If this doesn't work, then I would like to know how to store for example this data in binary way in one file and read it correctly back afterwards: three strings, one double, one float, two longs and three string arrays (one with 5, another with 3 and one with 10 string elements).

Upvotes: 0

Views: 371

Answers (1)

Konrad Gadzina
Konrad Gadzina

Reputation: 3404

You can create a new class that will contain those objects and then serialize an instance of this new class with values of it's fields set by values of those objects you're talking about. If you don't need those objects to be bound all the time, you can create an instance of this new class only just before the serialization and deserialization.

Upvotes: 2

Related Questions