title: Unsafe performance C# , remove long being cast to int to access array index
body: <p>Hi I got following code in C# unsafe where array is fixed</p>
  
  <pre><code>array[(int)(index)]
  </code></pre>
  
  <p>index is long (and has to be long for some reasons).. so I need to cast it to int in order to get access to array element. Is there a way to use pointers or some other combination of actions in unsafe code to prevent this cast cause index can have long value of 1 for example (and never exceeds int value obv)..
  I feel that maybe unsafe pointers addition could prevent it from happening. I also feel this cast is not for free..and performance is the issue here. (exactly this line)
  I also think its not possible but I ask just in case im mistaken.</p>
  
  <p>Ok ill give some more detail , im doing some required logical operations on long preIndex like</p>
  
  <blockquote>
    <p>value = array[(int)((preIndex &amp; mask ) >> 10)]</p>
  </blockquote>
  
  <p>those operations are required and code is fairly minimalistic already. Only thing I can find to be optimizable is this cast from long to int, cause bitwise operations are required.</p>
  
  <p>Thanks</p>