Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

vb.net collection - data type question - newbie

Posted on 2006-07-10
3
Medium Priority
?
313 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 1200 total points
ID: 17074779
for VB.NET use Hashtable
0
 
LVL 8

Assisted Solution

by:Shakti109
Shakti109 earned 400 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 400 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…

705 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