title: Shift property values of objects in an array
body: <p>I currently have a working method that shifts the values of one property of objects in an array:</p>
  
  <pre><code>    public class Group
      {
          public Position[] Positions { get; private set; }
  
          public void Shift()
          {
              var last = Positions[Count - 1].Tile;
              for( int i = Count - 1 ; i &gt; 0 ; i-- )
              {
                  // Note this shifts Tile value and not the array itself
                  Positions[i].Tile = Positions[i - 1].Tile;
              }
              Positions[0].Tile = last;
          }
      }
  
      public class Position
      {
          // [other properties]
  
          public Tile Tile { get; set; }
      }
  </code></pre>
  
  <p>The problem is that this method needs to run a lot in an algorithm and it is the one that consumes most CPU time.</p>
  
  <p>I'm searching for a better way to shift these values and found BlockCopy in this excellent answer: <a href="https://stackoverflow.com/a/52465132/1554208">https://stackoverflow.com/a/52465132/1554208</a></p>
  
  <p>But it's used to shift the array itself. Is there a way to copy the content of a property (here a simple pointer)?</p>
  
  <p>I'm open to:</p>
  
  <ul>
  <li>Use unsafe pointer methods</li>
  <li>Change the Position class if needed</li>
  <li>Any other suggestion</li>
  </ul>
  
  <p><strong>EDIT</strong></p>
  
  <p>Is there some way to "calculate" the size in bytes of a Position object, "calculate" the address of the Tile property within that object, and use something like Buffer.BlockCopy to copy these values at that specific address in the array?</p>