Pre-PS : it's too late to know that Vector3 is a value type; so the next post will not be very useful. Sorry for this mistake.
Well, although interfaces cannot have fields, they can have properties, for example:
interface IVector3 { double X { get; set; } double Y { get; set; } double Z { get; set; } }
In your Vector3 you simply implement things like everything else:
class Vector3 : IVector3 { double IVector3.X { get { ... } set { ... } } ... }
Now back to your position property. You bind the property to a fixed instance during initialization and provide only the recipient:
Vector3 position { get { return _position; } } private Vector3 _position = new Vector3(...);
By making the read-only property (i.e. no setter), you are sure that it will not be replaced by a new Vector3 object. Instead, you bind it to a fixed instance ( _position ) during initialization. But you can change Vector3 by assigning new values ββto position.X , position.Y or position.Z .
stakx source share