title: Problem in Unity: ArgumentOutOfRangeException: Index was out of range
body: <p>I always have the following problem when I execute the code in Unity:</p>
  <p><strong>ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
  Parameter name: index</strong></p>
  <p>The property Grid I set directly in the Unity editor with a value of 10 for x and y.</p>
  <p>public class World : MonoBehaviour
  {</p>
  <pre><code>public Room[,] Dungeon { get; set; }
  public Vector2 Grid;
  
  private void Awake()
  {
      Dungeon = new Room[(int)Grid.x, (int)Grid.y];
      StartCoroutine(GenerateFloor()); 
  }
  
  public IEnumerator GenerateFloor()
  {
      for (int x = 0; x &lt; Grid.x; x++)
      {
          for (int y = 0; y &lt; Grid.y; y++)
          {
              Dungeon[x, y] = new Room 
              {
                  RoomIndex = new Vector2(x, y) 
              };
          }
      }
      yield return new WaitForSeconds(3);
  
      Vector2 exitLocation = new Vector2((int)Random.Range(0, Grid.x), (int)Random.Range(0, Grid.y));
      Dungeon[(int)exitLocation.x, (int)exitLocation.y].Exit = true;
      Dungeon[(int)exitLocation.x, (int)exitLocation.y].Empty = false; 
      Debug.Log(&quot;Exit is at: &quot; + exitLocation); }}
  </code></pre>
  <p>I hope you can help me in this case</p>