Solved

vb.net collection - data type question - newbie

Posted on 2006-07-10
3
312 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying 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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

635 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