Just a follow-up on my post of yesterday about the intent of exposing a read-write property of an Array/Collection type.
Practical Guidelines and Best Practices has the following guidance (i'm paraphrasing)
13.13 To protect the state of a backing var for properties that return arrays, consider
get { return DirectCast(_arr.Clone(), string()); }
which is good protection, but less efficient. Or, provide indexed access to the array by an indexed property or function. Getting close...
13.14 Properties that return a collection should be read-only to prevent clients replacing the whole array with a new one, or with a null reference as that could break assumptions elsewhere in the class. Disco!
Thanks lads!
Powered by: newtelligence dasBlog 2.3.9074.18820
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.
© Copyright 2010, James Green
E-mail