• Real readonly lists in C#

    In C# there is the readonly keyword that enforced the rule that the variable must be initialised as it's declared or in the constructor. This works as expected for simple types, but for objects and lists it's not quite like that. With a list, you can still add, remove and change items in the list. You may also expose a list as a property with a public get and a private set. You want the owner class to be able to modify the list items, but you don't want anything outside the class to modify the list items.

    Here is an example with an almost readonly list, but as you can see it's not as readonly …