Solved

vb.net collection - data type question - newbie

Posted on 2006-07-10
3
310 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
ID: 17074779
for VB.NET use Hashtable
0
 
LVL 8

Assisted Solution

by:Shakti109
Shakti109 earned 100 total points
ID: 17074826

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
ID: 17075152
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB.NET 2008 Winforms Signing 13 32
How to install a font on WIN2003SBS/IIS 6 & test 17 33
VB.NET String Settings and Temp Folder Question 3 55
Passing data between Forms 3 20
This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
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 an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

830 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