I want several objects to exchange a link through a private field, so that any of the objects can assign this field, and the updated field will be visible to other objects using this link. I originally hoped to do this:
class SomeObject
{
private ref DataObject _data;
public SomeObject(ref DataObject data)
{
_data = ref data;
}
public ChangeData(DataObject newData)
{
_data = data;
}
}
But, of course, you cannot use it refas follows: it is refintended only for method parameters. And the static field will not work, since not all instances SomeObjectshould refer to the same object --- rather, the object in question must be set in the constructor.
Obviously, I could solve this by simply adding a simple wrapper class. But is there a better way? Is there any class SharedReference<T>I can use?
, , . , _data DataObject. . , , , , . , _data _data .