title: What does the VB.NET UBound function ACTUALLY do, and why does the MSDN documentation appear to be inaccurate?
body: <p><strong>What does the UBound function <em>actually</em> do in VB.NET, and why doesn't the MSDN documentation appear to be accurate?</strong></p>
  
  <p>According to the MSDN documentation (<a href="https://msdn.microsoft.com/en-us/library/95b8f22f%28v=vs.90%29.aspx" rel="nofollow noreferrer">here</a>) the UBound function: </p>
  
  <blockquote>
    <p>Returns the highest available subscript for the indicated dimension of an array.</p>
  </blockquote>
  
  <p>More specifically:</p>
  
  <blockquote>
    <p>The highest value the subscript for the specified dimension can contain. If Array has only one element, UBound returns 0. If Array has no elements, for example if it is a zero-length string, UBound returns -1.</p>
  </blockquote>
  
  <p>But, in my testing the (and in some examples found in the documentation) the UBound function returns the <strong>length</strong> of an array instead of the <strong>highest available subscript</strong>:</p>
  
  <p><img src="https://i.stack.imgur.com/Wu1R4.png" alt="Image from MSDN documentation on the UBound function"></p>
  
  <p><em>It's also important to note that UBound returns 1 for an Array containing one element, not 0 as the documentation states.</em></p>
  
  <hr>
  
  <p><strong>In response to an answer:</strong></p>
  
  <p>I now see that when you declare an array in vb.net you are declaring the highest desired subscript NOT the length of the array as in C#. </p>
  
  <p>Understanding that, I now understand why UBound was returning 1 instead of 0 for an array declared <code>Dim c(1)</code>. Because this array will have the highest subscript of 1 thus giving it 2 elements. Further, to declare an array with only one element in vb.net it should be declared like this <code>Dim b(0)</code>.</p>
  
  <p><img src="https://i.stack.imgur.com/iAPMq.png" alt="enter image description here"></p>