KeyValuePair<TKey, TValue> - member fields question
In looking at the source for the KeyValuePair<TKey, TValue>
struct, the private member fields are only ever written to by the construct开发者_如何转开发or. Is there a design consideration of some sort as to why these are not marked readonly
?
I do not believe there was any explicit design decision here. It was almost certainly an oversight by the original author of the code.
Also at the time of this types' authoring, the use of readonly
was a bit controversial for this scenario. A significant number of people felt it was bad practice to use readonly
on a non-immutable field. So much so that an FxCop rule was added to enforce this practice (CA2104). The type author could simply played by the rules of the time.
精彩评论