title: C# increase length of a string array
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/11767023/how-to-inset-a-new-array-to-my-jagged-array">how to inset a new array to my jagged array</a>  </p>
  </blockquote>
  
  
  
  <p>i have a problem, where i dont know how i can make a string array variable in array length.</p>
  
  <p>i have this code now below:</p>
  
  <pre><code>string[] p = new string[10];
  int num = 0;
  
  foreach (Product products in GetAllProducts())
      {
       //do something
       p[num]= "some variable result"
       num++
      }
  </code></pre>
  
  <p>The problem is, that i dont know how many of "p" i will get, although i know it atleast will be less than 10.
  but if i put it on 0, i will get an error when i start it, because it doesn't know the "p[num]"
  So i am looking for some way to make "p" have a variable length.</p>
  
  <p>anyone could help me out a bit? thanx</p>
  
  <p>============Solved==========</p>
  
  <pre><code>List&lt;string&gt; p = new List&lt;string&gt;();
  int num = 0;
  
  foreach (Product products in GetAllProducts())
      {
       string s= null;
       //do something ( create s out of multiple parts += s etc.)
       p.add(s)
       num++
      }
  </code></pre>
  
  <p>thanx to solution poster</p>