Solved

vb.net collection - data type question - newbie

Posted on 2006-07-10
3
306 Views
Last Modified: 2013-12-03
I am converting a vb6 application.

In it I use a collection of classes with the index being the number, in order that the class was added.

like

mycollection.add myclass, "1"

so I can loop through

for i = 0 to mycollection.count
   myclass.item(cstr(i))
next

Is there a better data type to use?

I don't remember why I used them in the first place, it could have been because there was no hash type.
0
Comment
Question by:jackjohnson44
3 Comments
 
LVL 35

Accepted Solution

by:
YZlat earned 300 total points
Comment Utility
for VB.NET use Hashtable
0
 
LVL 8

Assisted Solution

by:Shakti109
Shakti109 earned 100 total points
Comment Utility

There are a few limitations of using a "standard" collection, one of them is resizing (you have to manage the overall size yourself, etc).

You CAN use a hashtable, but there is no guarantee that you will always 100% get the itmes back out in the order you put them in (due to the hashing algorithm that makes hashtables so fast)  and the microsoft documentation is full of warnings to use your own algorithm to override the GetHashCode method, which most people (including myself quite often) ignore.

An alternative is to use an arraylist. The arraylist handles resizing itself, and you are guaranteed to get the items back out in the exact order they went in. The arraylist also has native methods for removing (removing at an index, and others), adding ranges, and a host of other native functions that standard collections don't.

0
 
LVL 24

Assisted Solution

by:Jeff Certain
Jeff Certain earned 100 total points
Comment Utility
If you're using VB2005, forget about the System.Collections namespace and move to Systems.Collections.Generic. Generics are strongly typed, so they provide a significant performance improvement (especially with value types, such as Integer) as well as reducing the number of run-time errors that occur, since those errors are now design-time errors.

Dim myCollection as List(of myClass)

For Each m as myClass in myCollection
' Do something with myClass
Next
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now