Serializing Objects

C# enables you to save an entire object, including all its data (called an object-graph) through a process called serialization. Serialization lets you write entire objects out to disk and read them back in later. Objects that pass between assembly boundaries (through a process called marshalling) are also serialized.

You use the BinaryFormatter class to serialize and deserialize objects; the significant public methods of this class appear in Table 5.19.

Table 5.19. Significant Public BinaryFormatter Methods
METHODDOES THIS
DeserializeDeserializes a stream into an object-graph.
SerializeSerializes an object to the given stream.

Here's an example, ch05_13.cs, which will serialize and deserialize an object. The ch05_13 class contains ...

Get Microsoft® Visual C#® .NET 2003 Kick Start now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.