Some people would suggest using a class type to hold the X and Y values. I am leery of that approach, and would suggest that in many cases the semantics obtained by exposing player as a field would be much cleaner (though I'm unclear why map has a member called player. If an map is reference to MapType, and instance of MapType has a field of struct type player, with a field x of type integer, it is clear that a change to map.player.x will affect one instance of MapType. Also, saying map1.player = map2.player; will copy the fields from map2.player to map1.player. By contrast, if player were of a class type and one did map1.player = map2.player; map1.player.x = 5;, that would affect both map1 and map2.
The question of whether to use a mutable struct versus a mutable class is pretty straightforward, but the notion of "If it's mutable make it a class" is just plain wrong. Simply ask yourself, given:
thing1 = thing2;
thing1.x = 5;
would you want the second statement to affect the value of thing2.x? If yes, use a class. If no, use a struct.
BTW, abother pattern to consider if you don't want your map type to expose player as a field would be to have it expose an ActOnPlayer method:
public delegate ActionByRef<T>(ref T p);
public delegate ActionByRef<T1,T2>(ref T1 p1, ref T2 p2);
public void ActOnPlayer(ActionByRef<playerType> proc;)
{
proc(ref _player);
}
public void ActOnPlayer<T>(ActionByRef<playerType,T> proc, ref T param;)
{
proc(ref _player, ref param);
}
... sample usage:
map.ActOnPlayer((ref playerType it, ref int theParam) ->
{it.x = theParam;}, someIntVariable);
Note that the latter approach would look something like using a closure, but unlike using a closure it would not generate any new temporary heap objects, and would thus not create any pressure on the garbage collector.
Pointreally have to have anything to do with the "standard"Pointin the .NET libraries? Mutable struct are evil. Avoid them unless you have a very good reason.