Code Inspection: Field can be made readonly (Private Accessibility)
Say you have decided to make an immutable Person
class, initialized only via the constructor. You go ahead and implement the following:
ReSharper can detect that private name
and age
fields are only being assigned in the constructor and offers to create an additional safeguard – by marking them readonly
, we get to ensure that this class will not inadvertently assign these fields anywhere within its methods.
Last modified: 12 October 2017