title: How to set array length in c# dynamically
body: <p>I am still new to C# and I've been struggling with various issues on arrays. I've got an array of metadata objects (name value pairs) and I would like to know how to create only the number of "InputProperty" objects that I truly need. In this loop I've arbitrarily set the number of elements to 20 and I try to bail out when the entry becomes null but the web service on the receiving end of this does not like any null elements passed to it:</p>
  
  <pre><code>private Update BuildMetaData(MetaData[] nvPairs)
  {
      Update update = new Update();
      InputProperty[] ip = new InputProperty[20];  // how to make this "dynamic"
      int i;
      for (i = 0; i &lt; nvPairs.Length; i++)
      {
          if (nvPairs[i] == null) break;
          ip[i] = new InputProperty();
          ip[i].Name = "udf:" + nvPairs[i].Name;
          ip[i].Val = nvPairs[i].Value;
      }
      update.Items = ip;
      return update;
  }
  </code></pre>
  
  <p>In summary, say I only have 3 namevalue pairs in the above input array? Rather than allocate 20 elements for the array called ip, how can code this so ip is only as big as it needs to be. The update object is passed across another webservice so serialization is important (i.e. I can't use namevaluecollection, etc.). </p>
  
  <p>p.s. Is the only way to followup on a posted question through the "add comments" facility?</p>