I was checking out the documentation of PureAttribute
in MSDN and I was surprised that it can be applied at class level. I knew what a pure function is, but I had never seen it applied to a type. In the MSDN documentation it states the following:
Indicates that a type or method is pure, that is, it does not make any visible state changes.
(bolded for highlighting purposes)
So my question is, if a pure type does not make any visible state changes, is that the same as an immutable type? Are both terms, if applied at the type level, equivalent? If not, can someone show me an example of a pure type that is not immutable or viceversa.
No, those are not the same:
An immutable type could have methods that mutate another object and this would not be pure.
On the other hand a type could expose mutable fields and yet only have pure methods that do not modify those fields.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With