I was reading XNA library code and inside the type VertexPositionColor, they supress the CA2105:ArrayFieldsShouldNotBeReadOnly message with the justification “The performance cost of cloning the array each time it is used is too great.”
public struct VertexPositionColor
{
public static readonly VertexElement [ ] VertexElements;
}
But why would it be copied when it’s used? This only happens for structs where the accessed property/field is a ValueType, right?
I guess they are justifying the fact that they are exposing an
arrayfieldmore than anything else and the underlying reason of why they are doing so is performance:The alternative they probably had in mind was making the
arrayfieldprivate with apropertyexposing anIEnumerableor returning a copy of thearrayeach time thepropertywas accesed.EDIT. Edited the answer a little to make clearer what I was trying to say :p.