title: C# volatile array items?
body: <p>I need an array with volatile items, and can't find a way to do that.</p>
  
  <pre><code>private volatile T[] _arr;
  </code></pre>
  
  <p>This means that the _arr reference is volatile, however it does not guarantee anything about the items inside the _arr object itself.</p>
  
  <p>Is there any way to mark the _arr's Items as volatile?</p>
  
  <p>Thanks.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>The following code built according to binarycoder's answer.
  Is this code thread-safe to use?</p>
  
  <pre><code>public class VolatileArray&lt;T&gt;
  {
      private T[] _arr;
  
      public VolatileArray(int length)
      {
          _arr = new T[length];
      }
  
      public VolatileArray(T[] arr)
      {
          _arr = arr;
      }
  
      public T this[int index]
      {
          get
          {
              T value = _arr[index];
              Thread.MemoryBarrier();
              return value;
          }
  
          set
          {
              Thread.MemoryBarrier();
              _arr[index] = value;
          }
      }
  
      public int Length
      {
          get { return _arr.Length; }
      }
  }
  </code></pre>