Why C# Arrays type IsSerializable property is True? Why C# Arrays type IsSerializable property is True? arrays arrays

Why C# Arrays type IsSerializable property is True?


Arrays does not have any Serializable attribute and also they aren't implement ISerializable interface

Array class, an implicit base class of C# arrays, has [SerializableAttribute]:

[SerializableAttribute][ComVisibleAttribute(true)]public abstract class Array : ICloneable, IList, ICollection,     IEnumerable, IStructuralComparable, IStructuralEquatable

(reference)

It also appears that the compiler adds [SerializableAttribute] to the array type itself

foreach (var a in typeof(string[]).GetCustomAttributes(false)) {    Console.WriteLine(a); // Prints "System.SerializableAttribute"}

Passing false to GetCustomAttributes ensures that only attributes for this class, and not for its base classes, are returned.

Demo.