C# Developers' Journal (original) (raw)

6:35p

In my senior thesis project, I've been coming across a difficulty:

Vector2 v = s.Velocity;
s.Position = new Point(x, y);
s.Velocity = v;

Looks fine, right? However, there is a problem. When I assign the variable "v", I'm really aiming to preserve the value of "Velocity". However, the variable "Velocity" automatically becomes zero when "position" is defined. Therefore, when I re-assign the value of "Velocity", I get zero because the variable "v" is a reference.

In short, how do I copy a variable for its exact value at that time, and not as a reference?