Source: https://msdn.microsoft.com/en-us/library/bb383979.aspx

There are two methods to make an immutable property:

  1. Declare private setter (class becomes immutable to consumers)
  2. Declare only getter (property is immutable and it can only be set in the class constructor)

Learned something new today: I’ve always used method 1, but one of my coworkers submitted a pull request using method 2. So I’ve hit the books 🙂

Advertisements