SerializableAttribute Class

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

Indicates that a class can be serialized. This class cannot be inherited.

System..::..Object
  System..::..Attribute
    System..::..SerializableAttribute

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

[AttributeUsageAttribute(AttributeTargets::Class|AttributeTargets::Struct|AttributeTargets::Enum|AttributeTargets::Delegate, Inherited = false)]
public ref class SerializableAttribute sealed : public Attribute

The SerializableAttribute type exposes the following members.

  NameDescription
Public methodSerializableAttributeInitializes a new instance of the SerializableAttribute class.
Top

  NameDescription
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

Apply the SerializableAttribute attribute to a type to indicate that instances of this type can be serialized. The common language runtime throws SerializationException if any type in the graph of objects being serialized does not have the SerializableAttribute attribute applied.

Apply the SerializableAttribute attribute even if the class also implements the ISerializable interface to control the serialization process.

When you apply the SerializableAttribute attribute to a type, all private and public fields are serialized by default. You can control serialization more granularly by implementing the ISerializable interface to override the serialization process.

Or you can exclude fields from serialization by applying the NonSerializedAttribute attribute to the field. If a field of a serializable type contains a pointer, a handle, or some other data structure that is specific to a particular environment, and cannot be meaningfully reconstituted in a different environment, then you might want to apply the NonSerializedAttribute attribute to that field.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show: