title: Making an array of an unknown size C#
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/599369/array-of-an-unknown-length-in-c-sharp">Array of an unknown length in C#</a>  </p>
  </blockquote>
  
  
  
  <p>I want to create a program where users can input there items and those items will be stored in an array. When the user is okay with the amount of items, the program will ask for every item if he got it.</p>
  
  <p>The problem is i cant seem to create an array that is of unknown size. I tried to use something like this: <code>String[] list = new string[]{};</code> But when the program goes there it gives an IndexOutOfRangeException.</p>
  
  <p>Is there a way i can do this?</p>
  
  <p>This is the full code:</p>
  
  <pre><code>bool groceryListCheck = true;
          String[] list = new string[]{};
          String item = null;
          String yon = null;
          int itemscount = 0;
          int count = 0;
  
          while (groceryListCheck)
          {
              Console.WriteLine("What item do you wanna go shop for?");
              item = Console.ReadLine();
              list[count] = item;
              count++;
              Console.WriteLine("Done?");
              yon = Console.ReadLine();
              if (yon == "y")
              {
                  groceryListCheck = false;
                  itemscount = list.Count();
              }
              else
              {
                  groceryListCheck = true;
              }
          }
  
          for (int x = 0; x &lt; itemscount; x++)
          {
              Console.WriteLine("Did you got the " + list[x] + "?");
              Console.ReadKey();
          }
  </code></pre>