Avoid non-zero based integral indexers for collections

I am clearing out a backlog of Design Guidelines issues…


face=Verdana>Do use zero based indexes if the
collection is integral indexed.

style="BACKGROUND-COLOR: #e9fdf3">Annotation (BradA): In
designing the first version of the .NET Framework we went around and around on
using zero or one based indexes for collections.  There was tons of prior
art for both, for example the C derived languages (C, C++, etc) where all zero
based and the VB world was one based.  Early on we made a call that arrays
would be zero based and built that assumption deep into the implementation
making collections that are 1 based harder to implement in a performant
But at this point the most impotant reason to make sure integral
indexed collections are zero based is simply consistency with the rest of the

style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">


Comments (1)

  1. Anonymous says:

    VB was NOT zero based – it could be either (via Option Base IIRC). I always used 0 based arrays, and so did just about all the code I saw I think.

    I agree that the theoritical arguments between 0 and 1 a pretty slim, but I think overwhelmingly usage is 0-based.