Avoid non-zero based integral indexers for collections

I am clearing out a backlog of Design Guidelines issues...

 

Do use zero based indexes if the collection is integral indexed.

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 way. 
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 platform.

 

Published 01 December 03 11:29 by BradA

Comments

# Anonymous said on December 1, 2003 12:44 PM:
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.
New Comments to this post are disabled

Search

Go

This Blog

Syndication

Page view tracker