Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
Ive just been looking through the object browser and collections are a member of Microsoft.VisualBasic is there a system object that has the same methods (or similar etc) to the VB Collection object?

Phil Price�

Visual Studio .NET 2003 Enterprise Edition

Microsoft Student Partner 2004

Microsoft Redmond, EMEA Intern 2004

  • *Experts*
Posted

Try a Hashtable.

 

-ner

"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
Posted
hashtables alow objects to be put into groups?

Phil Price�

Visual Studio .NET 2003 Enterprise Edition

Microsoft Student Partner 2004

Microsoft Redmond, EMEA Intern 2004

  • *Gurus*
Posted

ArrayList is pretty much the most general-purpose collection class in the framework, I'd say. The HashTable is useful if you need a collection of name-value pairs.

 

You are encouraged to inherit from CollectionBase to make your own strongly-typed collections :)

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted
divil, any thing on msdn / the webby for writing your own?

Phil Price�

Visual Studio .NET 2003 Enterprise Edition

Microsoft Student Partner 2004

Microsoft Redmond, EMEA Intern 2004

  • *Experts*
Posted

If you want an object that works like VB6's Collection, then a Hashtable is very similar, assuming you want to put objects in and retreive them by a Key. .NET supports many types of "collections", such as a Stack, a Queue, the ArrayList, Hashtable, and more. Plus, as divil mentioned, you can create your own collection objects that are type-safe.

 

-Nerseus

"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
Posted

I just want the a structure so i can do

 

For each objectType in collection

..

Next

 

I'll look in to the options later on today. Thanks guys.

Phil Price�

Visual Studio .NET 2003 Enterprise Edition

Microsoft Student Partner 2004

Microsoft Redmond, EMEA Intern 2004

Posted
I just want the a structure so i can do

 

For each objectType in collection

..

Next

 

I believe it's the IEnumberable interface which supports this, so anything that implements that interface supports for each. What I'm getting at, is that you can do a for each with a basic array, you don't need a collection.

Gamer extraordinaire. Programmer wannabe.
Posted
But i want to use collections as the .add and .remove methods are really useful along with .count because i have a collection of classes with collections inside, i think with arrays you have to do needless group work just to add the functionalility you want, unless arrays are treaten as objects like they are in java...

Phil Price�

Visual Studio .NET 2003 Enterprise Edition

Microsoft Student Partner 2004

Microsoft Redmond, EMEA Intern 2004

Posted
Everything in .NET is an object. Look up the Array object in the object browser. Instead of Count, though, the property is Length. Also an Array is not dynamic either, so obviously there is no Add or Remove method. Use Array for a static list of elements, ArrayList for dynamic list.
Gamer extraordinaire. Programmer wannabe.
Posted
okay im going to look into it in a mo.

Phil Price�

Visual Studio .NET 2003 Enterprise Edition

Microsoft Student Partner 2004

Microsoft Redmond, EMEA Intern 2004

  • *Experts*
Posted

Here's an example of a static control array that Wyrd is refering to:

 

Public Sub HideAllBorders()

Dim ctr As Control

Dim Border As Panel

For Each ctr In Me.grpConversionTypes.Controls

If TypeOf ctr Is Panel Then

For Each Border In Borders

Border.Visible = False

Next

End If

Next

End Sub

 

Where Borders is the control array.

Member, in good standing, of the elite fraternity of mentally challenged programmers.

 

Dolphins Software

Posted

Actually I was just talking about regular old Arrays..

 

char[] someString = new char[50];

 

That's a static array object *shrug*

 

..since you mentioned it.. :) Aren't control arrays dynamic? You can add/remove controls from control arrays right?

 

On a side note, good example.. I forgot about control arrays and how you can loop through those too, etc. Heh.

Gamer extraordinaire. Programmer wannabe.
Posted

Okay ive done it with Inheriting CollectionBase, and it works nicely :), just one question, you have to overload onSet() etc, which is no problem, but you need to compare the type and thorw and error if it doesnt match, this again is okay, but the only way i could nicely get the type is..

 

  Private story As New RSSStory
   Private storyType As Type = Type.GetTypeFromHandle(Type.GetTypeHandle(story))

 

Which is okay, but im sure there is a better way of doing it??

Phil Price�

Visual Studio .NET 2003 Enterprise Edition

Microsoft Student Partner 2004

Microsoft Redmond, EMEA Intern 2004

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...