How can I protect a list in a class to not have items added or removed in C#?
I have a class Header that consists of a list of Line
public class Line
public class Header
public List<Line> Lines;
I want consumers to able to edit the individual Lines, but not Add or Remove Lines items. This because Header must have full control on Add and Remove (of Lines) because of processing rules. It should not allowed for a consumer to initialize Lines either.
I still want consumers to have all the other benefits of a List.
I dont want to create an error message, but to hide these methods from consumers of the class.