- Start by adding an abstract class called Cat. This class simply defines fields for Weight and Age. Note that in order to make your class serializable, you need to add the [Serializable] attribute to it.
[Serializable] public abstract class Cat { // fields public int Weight; public int Age; }
- Next, create a class called Tiger that is derived from the Cat class. Note that the Tiger class must also have the [Serializable] attribute added. This is because the serialization isn't inherited from the base class. Each derived class must implement serialization on its own:
[Serializable] public class Tiger : Cat { public string Trainer; public bool IsTamed; }
- Next, we need to create a method to serialize the Tiger class. ...