title: Properly copying data around in C#
body: <p>I'm working on some simulation code in C#, and I have some code along the lines of:</p>
  
  <pre><code>public void predict(Point start, Point end)
  {
      end.velocity = start.velocity + dt * end.acceleration;
      end.position = start.position + dt * end.velocity;
  }
  </code></pre>
  
  <p>Where position, velocity, acceleration are some vector data types I defined with associated operators.</p>
  
  <p>As well as code where I'm doing:</p>
  
  <pre><code>StartPoint = EndPoint;
  EndPoint = CurrentPoint;
  </code></pre>
  
  <p>With the *Points being instances of Points that have several primitive (double) and non-primitive (Vector) data types.</p>
  
  <p>I'm running into the (obvious) issue that the above code, most likely will simply just set StartPoint to point to the data that was previously EndPoint, and EndPoint will point to CurrentPoint.</p>
  
  <p>Meaning, if I modify CurrentPoint again I'll end up accidentally modifying EndPoint.</p>
  
  <p>In C++ this is simple to prevent since I can define my assignment operator to do a deep copy of the underlying data within my Point objects. How can I prevent this in C#?</p>
  
  <p>Thanks for any help!</p>
  
  <p>Edit: The Vector class is defined as</p>
  
  <pre><code>[Serializable]
  public class Vector
  {
      private Double[] data = new Double[Constants.Dimensions];
  
      ... snip ...
  
      public static Vector operator +(Vector lhs, Vector rhs)
      {
          Vector result = new Vector();
          for (UInt32 i = 0; i &lt; Constants.dimensions; i++)
              result[i] = lhs[i] + rhs[i];
          return result;
      }
  
      lots more code here 
  }
  </code></pre>