title: Fastest way to add an Item to an Array
body: <p>What is the fastest way to add a new item to an existing array?</p>
  
  <pre><code>Dim arr As Integer() = {1, 2, 3}
  Dim newItem As Integer = 4
  </code></pre>
  
  <p>(I already know that when working with dynamic list of items you should rather use a <code>List</code>, <code>ArrayList</code> or similar <code>IEnumerables</code>. But what to do if you're stuck to legacy code that uses arrays?)</p>
  
  <p>What I've tried so far:</p>
  
  <pre><code>' A) converting to List, add item and convert back
  Dim list As List(Of Integer)(arr)
  list.Add(newItem)
  arr = list.ToArray()
  ' --&gt; duration for adding 100.000 items: 33270 msec
  
  ' B) redim array and add item
  ReDim Preserve arr(arr.Length)
  arr(arr.Length - 1) = newItem
  ' --&gt; duration for adding 100.000 items: 9237 msec
  
  ' C) using Array.Resize
  Array.Resize(arr, arr.Length + 1)
  arr(arr.Length - 1) = newItem
  ' --&gt; duration for adding 100.000 items: 1 msec
  ' --&gt; duration for adding 100.000.000 items: 1168 msec
  </code></pre>
  
  <p>A) seems very slow since every time an item is added two conversions of the whole array are done. B) seems faster but still the array is copied once during the <code>ReDim Preserve</code>. C) seems to be the fastest at this point. Is there anything better?</p>