Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Is it true to say that every type of grouping class (collection, array, hashtable etc.) is zero based in VB.net, except for the collection class which is 1 based? I note in particular that the IList contained in the List property of CollectionBase is 0 based. I find this a bit annoying. If I have a collection and then decide I need to make it strongly typed by having a class inheriting from CollectionBase I either have to change all item references in my code or have the following rather awkward code in the new class:

 

   Public Function item(ByVal i As Integer) As String
       Return MyBase.List.Item(i + 1)
   End Function

 

Any thoughts?

Posted (edited)

The Collection class in VB is a visual basic specific class (it is in the Microsoft.VisualBasic namespace) and is probably there for the comfort factor alone. All of the other "grouping" classes are part of the larger .Net Framework, which all .Net languages use, and which specifies that array types are 0 based.

You should probably get used to using the 0 based classes, and thus instead of using the code above, just make changes when using the collection class.

Edited by IceAzul
  • Leaders
Posted
1-based collections are an oddity mostly unique to VB. As far as I can remember all other version of Basic and all other languages I have ever used have 0-based arrays and collections, and in the end it is simpler and more logical. At the moment you might not agree with that, but maybe once you get used to it you will appreciate it.
[sIGPIC]e[/sIGPIC]
  • 2 weeks later...
Posted
I certainly think that consistency across classes is the best thing. I may well stop using the Collection class since it's a pain to have to keep thinking "Now is this a zero based or 1 based index?". If it's always zero then that is a lot easier for me.
  • *Experts*
Posted

It's too bad they didn't make a few more classes 1-based alongside their 0-based brethren. I love those mix-and-match base indexes!

 

Oh wait, I hated those in VB6! Go go dot net gadget!

 

-nerseus

 

PS I'm just in a chipper mood today. And not a Fargo-like chipper either.

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...