I need a class to store a mutable value. When an instance of this class is shared between different parts of code and one part changes the value inside that object, all the other parts see the new value.
This question isn't how I could write it. Here it is for anyone searching:
public class ValueHolder<T> { public T Value { get; set; } }
My question is, does this class exist anywhere in the standard library? This feels like something that would be included in the many small classes it provides.
Or, is there another way I could achieve my required outcome without littering my code with small classes?
Update/Commentary:
I'm a little bit surprised by the amount of negativity this question raised.
"This leads to a high WTF count!" "You are reinventing!"
Reinventing was something I explicitly set out to avoid in asking this question. If there was something in the standard library already, I could use that instead of writing a new class. (So long as the benefits outweighed the costs.)
The technique, passing an object and allowing it to be modified, is used all the time. Have you ever written a function that takes a List in order for that function to add/remove values? What about an event handler (such as Form.Closing) that allows the event handler to change the ongoing event by setting a value inside the event-args object?
In my case, the object was just a class with a single bool value in it. It gets passed into another piece of code in order to allow that flag to be raised or lowered. You might say that this should be a function's return value or a ref parameter, but I'm using a framework which allows for objects to be passed along to handlers (similar to ParameterizedThreadStart or the Tag properties) so I'm limited in what I can pass around.
"I wonder if the standard library already has a class that does this." I thought to myself. "Let's find out!"