In looking at the source for the KeyValuePair<TKey, TValue> struct, the private member fields are only ever written to by the constructor. Is there a design consideration of some sort as to why these are not marked readonly?
In looking at the source for the KeyValuePair<TKey, TValue> struct, the private member fields
Share
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
readonlywas a bit controversial for this scenario. A significant number of people felt it was bad practice to usereadonlyon 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.