title: How should I pass an array by value? Isn't Clone() discouraged?
body: <p>I've been debugging a C# program of mine, and after several fruitless spans of time, discovered the error came from &quot;accidentally&quot; passing an array by reference instead of by value.</p>
  <p>Here's some pseudocode:</p>
  <pre><code>//1st pass
  currentVertices = levels[0].vertices;   
  currentVertices[0].Position.Z -= 10;
  
  //2nd pass
  currentVertices = levels[1].vertices;
  currentVertices[0].Position.Z -= 10;
  
  //3rd pass
  currentVertices = levels[0].vertices;
  currentVertices[0].Position.Z -= 10;  
  
  //currentVertices[0].Position.Z is now 10 less than expected;
  //20 less than it started. Further loops will increase the difference in expected
  //value.
  </code></pre>
  <p>I was not expecting to have passed the Array by reference, but I accidentally did so anyway.</p>
  <p>Is there a way to assign an array by <em>value</em> instead of by reference? I know that I could iterate through both arrays, assigning each term individually, but that seems unnecessarily complex. I'm reasonably sure that the Clone() function, well, clones, the values without the respective references, but is that the only way to assign by value? I.e. <code>currentVertices = levels[1].vertices.Clone();</code></p>
  <p>Isn't Clone() generally discouraged? What's the best practice for passing arrays by value?</p>
  <p>In the short term, I've simply hardcoded what the values should be after being loaded.</p>
  <p><a href="https://chat.stackexchange.com/transcript/message/2570775#2570775">As one of my moderator friends remarked,</a></p>
  <blockquote>
  <p>&quot;I see you solved pass-by-reference through by-pass-reference.&quot;</p>
  </blockquote>