One annoying quirk in .net is that unless one is using "unsafe" code the concept of a value-type array does not exist. The struct as shown contains a position for the "pacman" and a reference to a mutable array that holds the positions of the ghosts. This is an evil combination, since the struct may appear to encapsulate the positions of the ghosts, but it does not. Thus, if one were to say:
StartPositions p1 = whatever();
... do some stuff
StartPositions p2 = p1;
p2.pacman.X += 3;
p2.ghosts[0].X += 3;
the code would add three to p2.pacman
and p2.ghosts[0]
; it would not affect p1.pacman.X
but would add three to p1.ghosts[0]
. Such behavior would likely cause confusion.
If your intention is that StartPositions
will be read-only, it should probably never expose the ghosts
array directly; instead, ghosts
should be a property of type IList<Vector2>
, and your constructor should set it to something like a new ReadOnlyList<Vector2>
initialized with a copy of the passed-in positions. If it does that, then ghosts
can simply be a read-only property that returns such positions.