Marks a class or struct as being serializable.
[serializable]
Class and struct declarations.
serializable is a single-use attribute. Serializable is an alias for System.Serialization.SerializableAttribute.
The base class library provides serialization services only to classes and structs with the serializable attribute. In the example below, the fact that class SerialExample
is marked serializable and has a member of type Serial2
does not automatically confer the serializable attribute to class Serial2
.
Within a serializable class or struct, individual fields can be marked nonserialized to prevent them from being serialized.
[serializable] public class SerialExample { int a; Serial2 x; [nonserialized] int temp; // don't bother to serialize this field } [serializable] // have to make this serializable too public struct Serial2 { string s; }