How it works...

After you run your code, you will find that the vehicleInfo.dat file has been created at the path you specified:

Opening the file in a text editor will show the serialized information.  As you may notice, some of the class information is still visible:

If we add a breakpoint in the deserialization code and inspect the created deserializedVehicle object, you will see that the Vehicle state has been rehydrated to the state it was before serialization:

Get C# 7 and .NET Core Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.