title: C# multidimensional array in line
body: <p>I'm writing a class to hold a three-dimensional array as a one-dimensional.</p>
  
  <p>I have a bug in the code: all writen elements when the size of the array 1x1 (xz) are null.</p>
  
  <p>Tell me where is the mistake and tell me what libraries already for this?</p>
  
  <pre><code>public class Arr3D&lt;T&gt; {
  
  private T[] arr;
  private Vector3 min, max;
  private Vector3 size;
  
  public Arr3D() 
  {
      arr = new T[0];
  }
  
  public void AddOrReplace(T obj, Vector3 pos) 
  {
      Vector3 newMin = Vector3.Min(min, pos); // ( Min(x1,x2), Min(y1,y2), ...
      Vector3 newMax = Vector3.Max(max, pos+Vector3.one); // +(1,1,1)
  
      if(newMin != min || newMax != max) 
      {
          Resize(newMin, newMax);
      }
  
      Set(obj, pos);
  }
  
  public void Set(T obj, Vector3 pos) 
  {
      Set(obj, pos.x, pos.y, pos.z);
  }
  
  public void Set(T obj, int x, int y, int z) 
  {
      arr[ (y-min.y)*size.x*size.y  +  (z-min.z)*size.x + (x-min.x) ] = obj;
  }
  
  private void Resize(Vector3 newMin, Vector3 newMax) 
  {
      Vector3 oldMin = min;
      Vector3 oldMax = max;
      T[] oldList = arr;
      Vector3 oldSize = size;
  
      min = newMin;
      max = newMax;
      size = newMax - newMin;
      arr = new T[size.z*size.y*size.x];
  
      for(int x=oldMin.x; x&lt;oldMax.x; x++) 
      {
          for(int y=oldMin.y; y&lt;oldMax.y; y++) 
          {
              for(int z=oldMin.z; z&lt;oldMax.z; z++) 
              {
                  T val = oldList[(y-oldMin.y)*oldSize.x*oldSize.y  +  (z-oldMin.z)*oldSize.x + (x-oldMin.x)];
                  Set(val, x, y, z);
              }
          }
      }
  
  }
  
  public T Get(int x, int y, int z) 
  {
      return arr[(y-min.y)*size.x*size.y  +  (z-min.z)*size.x + (x-min.x)];
  }
  }
  </code></pre>