How to do it...

  1. Create a class called Vehicle. You will notice that this class implements ISerializable while still having the [Serializable] attribute. You must do this so that the Common Language Runtime can identify this class as serializable:
        [Serializable]        public class Vehicle : ISerializable        {        }
  1. To this class, add the following fields and the constructor:
        // Primitive fields        public int VehicleType;        public int EngineCapacity;        public int TopSpeed;        public Vehicle()        {        }
  1. When you implement ISerilizable on your Vehicle class, Visual Studio will alert you that the ISerializable interface has not been implemented inside your class. Add the implementation by clicking on the lightbulb next to the underlined interface name and accepting ...

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.