Object Serialization in Visual Basic.NET: Demo

Category:
C#, VB.NET, ASP.NET
Type:
Modules
Difficulty:
Advanced

Author: Pramod Kumar Singh

Version Compatibility: Visual Basic.NET

More information:
This sample demonstrates the runtime's ability to serialize an object in memory to disk. It also shows how to implement a linked list in VB.NET.

A singly-linked linked list is created, filled with values, and serialized to a file on disk. The list is then deserialized from the file on disk, restoring it to an object in memory. The elements within the list are then swapped multiple times.

Note that Option Strict is off in this module, because it uses casting of object while doing deserialization from disk to memory object.

To get this code to work, create a new Application in Visual Basic.Net. Add a module, copy the code below into that module. Then right-click the project name, select properties, and select Sub Main as the startup object.

Note that this illustrates binary serialization of an object. XML serialization is also possible; binary serialization makes it harder to read the object's property's outside of a .NET application, which can be an advantage or a disadvantage depending on your needs.

This demo, originally developed for VB.NET Beta 1, was modified to support VB.NET version 1.0 on 04/01/02.

Instructions: Copy the declarations and code below and paste directly into your VB project.

Declarations:

Code: