O'Reilly logo

Microsoft® Visual Basic® .NET Programmer's Cookbook by Matthew MacDonald

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Create a Serializable Object

Problem

You need to create an object that can be serialized (converted to a stream of bytes).

Solution

Add the Serializable attribute to your class.

Discussion

Serializable objects can be converted into a stream of bytes and recreated at a later point in time. You can use serialization to save an object to disk (as explained in recipe Serialize an Object to Disk) or to send an object between application domains with .NET Remoting (in which case, the .NET runtime manages the serialization and deserialization transparently).

In order for serialization to work, your object must meet all the following criteria:

  • The object must have a Serializable attribute preceding the class declaration.

  • All the public and private variables of ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required