tags:

views:

84

answers:

1

If I add the [Serializable] attribute to a class, does this introduce any overhead? How about if the class is never used in any serialization operations?

+8  A: 

This doesn't add any overhead to the normal runtime use of the object.

Marking a class as Serializable doesn't even result in a size difference in metadata. It just sets a bit in the typedef flag. (Thanks to thecoop for pointing that out)

JaredPar
It doesn't actually add overhead; `SerializableAttribute` is a special pseudo-attribute that sets the `Serializable` bit in the `TypeDef` flags. So it doesn't add any metadata overhead.
thecoop
@thecoop, interesting had no idea abouth that. Updated my answer.
JaredPar
@JaredPar: Out of curiosity, what part of .NET are you working on? Just wondering.
Joan Venge
@Joan, I used to work on the C# and Vb.net languages team but now work on a language and operating system incubation project.
JaredPar
@JaredPar: Thanks Jared. Thought you had something to do with C# .NET so wanted to make sure if I remember it correctly. Cheers.
Joan Venge