If a class variable or struct-type provides a field of type value, and this type of value provides its contents in the form of fields, operations on these fields can be performed as effectively as operands by type of environment. If the value type is displayed as a property, then the best thing you can do is generally something like:
var temp = t.Location; temp.X += 4; t.Location = temp;
Not very elegant, but relatively clear and not too terribly inefficient. An alternative would be for the tank to expose the AdjustLocation method, something like:
delegate void ActByRef<T1>(ref T1 p1); void ActOnLocation(ActByRef<Point> proc) { proc(ref _Location); }
and probably also
delegate void ActByRef<T1,T2>(ref T1 p1, ref T2 p2); void ActOnLocation<PT1>(ActByRef<Point, PT1>, ref PT1 param1) { proc(ref _Location, ref param1); }
These methods assume that the Location property uses a support field named _Location . The code could then do something like:
// Add 5 to X myTank.ActOnLocation( (ref Point loc) => loc.X += 5 );
or
// Add YSpeed to Y myTank.ActOnLocation( (ref Point loc, ref int param) => loc.Y += param, ref YSpeed);
Note that in the latter case, neither YSpeed , nor this , nor any other local variable is used in lambda; instead, YSpeed is passed as the ref parameter. Because of this, even if the above code is run a million times, the system will only need to create one delegate, which can then be reused each time.
If the structure was large, the above approach may be faster than the approach using a temporary variable. Although the overhead probably exceeds the cost of copying a small structure, the overhead does not depend on the size of the structure. Structures that are several kilobytes in size can be efficiently used if constructions like the one above are used to avoid the need to make temporary copies.