Collection -- zero-based or one-based?

Yuliya

Active member
Joined
Nov 9, 2007
Messages
34
Programming Experience
Beginner
I always thought Collection was zero-based. I've been using built in collections, like DataSet table rows, and they are zero-based.

Then I tried to create my own collection of Objects, and got an exception because I tried to access MyCollection(0).

So is it one-based, or zero-based? And why??

Thank you.
 
It's zero-based. Perhaps you didn't have any items?
 
I had items. Moreover, when I looked at the collection in the watch window, it showed the first cell saying something like "Placeholder to keep the collection one-based."

What's going on?
 
That is very strange. What are you talking about actually? I think you must tbe using the Microsoft.VisualBasic.Collection, which is a VB6 compability class. If this is the case you should not use this class, look for info in System.Collections and System.Collections.Generic namespaces. From .Net 2.0 you should in most cases only need the latter.
 
Back
Top