How would I create a property in a class that can only be set using an addition assignment. I know events work this way in C#. I was wondering how I may implement the construct in my own code.
Eg. For Events I can do the following
public event EventHandler myEventHandler;
myEventHandler += NewEvent;
And that will add NewEvent to the chain of events that gets run when myEventHandler is called.
I want to be able to do something similar. I want to create a Graph class which models mathematical graphs with nodes and connections. The Graph class would have a nodes property which should only be able to have nodes added or removed but not set as a whole property.
Once again using the EventHandler example, I can't do the following with EventHandler
myEventHandler = OnlyOneEventWillRun;
I also want to be able to implement logic to the addition assignment similar to the set{} accessor.
+=in there