title: Receiving an error, Collection was modified; enumeration operation may not execute, but I don't know what I am doing wrong and where?
body: <p>Here is the code</p>
  <pre><code>List&lt;Vector2Int&gt; startPos = new();
          startPos.Add(new(5, 5));
          for (int i = 0; i &lt; 2; i++)
          {
              var something = FloodFill(startPos);
              foreach (KeyValuePair&lt;Vector2Int, string&gt; kv in something)
              {
                  Debug.Log(kv.Key);
              }
              startPos.Clear();
              List&lt;Vector2Int&gt; vector2Ints = new(something.Keys);
              startPos = vector2Ints;
          }
  </code></pre>
  <p>The above code is the code that I used and it's showing an error. Perhaps there is an error in the above part but for reference, I am also attaching the Floodfill function that I have written.</p>
  <pre><code>Dictionary&lt;Vector2Int, string&gt; FloodFill(List&lt;Vector2Int&gt; startPos)
      {
          Dictionary&lt;Vector2Int, string&gt; returnList = new();
          foreach (Vector2Int pos in startPos)
          {
              returnList.Add(pos, &quot;Anything&quot;);
          }
          
          List&lt;Vector2Int&gt; nextIterationList = new(startPos);
          List&lt;Vector2Int&gt; tempList = new();
          foreach (Vector2Int point in nextIterationList)
          {
              for (int m = 0; m &lt; 3; m++)
              {
                  tempList.Add(new(point.x - 1, point.y + (m - 1)));
                  tempList.Add(new(point.x + 1, point.y + (m - 1)));
                  if (m == 1)
                  {
                      continue;
                  }
                  tempList.Add(new(point.x, point.y + (m - 1)));
              }
              foreach (Vector2Int dot in tempList)
              {
                  if (returnList.ContainsKey(dot))
                  {
                      tempList.Remove(dot);
                  }
                  else
                  {
                      returnList.Add(dot, &quot;Anything&quot;);
                  }
              }
          }
          return returnList;
      }
  </code></pre>
  <p>The error that I am receiving is
  <strong>Collection was modified; enumeration operation may not execute.
  System.Collections.Generic.List<code>1+Enumerator[T].MoveNextRare () (at &lt;31c0f51ac5a24a22ba784db24f4ba023&gt;:0) System.Collections.Generic.List</code>1+Enumerator[T].MoveNext () (at &lt;31c0f51ac5a24a22ba784db24f4ba023&gt;:0)</strong></p>