At this point, every data member contained within the StateInfo class will be serialized and written to disk. However, there may be times when a certain variable does not need to be serialized. To prevent a variable from being serialized, apply the NonSerialized attribute to each data member that doesn't need to be serialized. As you may have guessed, the private member variable m_pstrNonSerialized will be marked as nonserialized, so apply the NonSerialized attribute to that variable, as shown on line 51 of Listing 24.2. The process of marking individual members as nonserialized is known as selective serialization.
You can further customize the serialization process by implementing the ISerializable interface defined within the .NET Framework and providing an implementation of the GetObjectData function declared in that interface. This allows you to specify the data that will be serialized rather than relying on the current value of that variable. An obvious question is why you would ever want to do that. If you have a member variable whose value would be considered invalid after the deserialization process but still needs a special value to successfully reconstruct that object, you would perform this process, which is known as custom serialization. For this hour, however, we are just going to use selective serialization.