HashTable vs Jagged Array

NeuralJack

Centurion
Joined
Jul 28, 2005
Messages
138
HashTable vs Jagged Array for an array of arrays[vb.net]

I have a custom class which holds about 8 different variables of differing types. I need to create various Arrays of those classes... but i'd also like to sort all of those arrays for easier programming by enumerating those arrays.
Is Hashtable a low-system resource thing or what? I'd like to simply use a jagged array but the documentation says they're not CLS compliant.

I'm wondering what the best solution to this is, performance is probably an issue.
Is there a simple way to enumerate class arrays?
 
Last edited:
Thanks PD , the generic class "List" seems to be perfect.

PlausiblyDamp said:
As you are using .Net 2 then you might want to investigate generics as an alternative to both arrays / HashTables.
 
Actually, I spoke too soon. I'm having the same problem figuring out how to declare and initialize an array of an array with List as I am with other types of arrays. Any help with the syntax would be appreciated.
Lets say I need an array of an array of this class:
Visual Basic:
Public Class AnyClass
Public int1 As Integer = 0
Public int2 As Integer = 1
Public str1 As String = String.Empty
Public str2 As String = String.Empty
End Class

This has evolved mainly into a syntax question , i think. Eventually I want to be able to access one of the entries like:
Visual Basic:
Integer2 = ArrayOfArrays(1)(1).int2

Lets say I want to make 2 different Array of Arrays We'll name them ArrayOfArraysOne And ArrayOfArraysTwo. In ArrayOfArraysOne I want 5 different Arrays of the class AnyClass. Lets say the subarrays in that array need 5, 3, 3, 4, 5 elements in each of those subarrays.

In ArrayOfArraysTwo I want 10 different Arrays of the class AnyClass.Lets say the subarrays in that array need 1, 2, 3, 4, 5 elements in each of those subarrays.

I'd, ideally, like to use the List object from System.Collections.Generic.. which doesnt look all that different to implement than other arrays.
 
Ok, i've figured this out after lots o trial and error. To create an array of arrays with the generic List obect do this. The array will be an array of arrays of the class 'AnyClass'.



Visual Basic:
'The Class:
Public Class AnyClass
Public int1 As Integer = 0
Public int2 As Integer = 1
Public str1 As String = String.Empty
Public str2 As String = String.Empty
End Class 



'To Declare:
Public ArrayOfArrays As List(Of List(Of AnyClass)) = New List(Of List(Of AnyClass))(2)  

'To Initialize:
For i As Integer = 0 To 1  'Add 2 Subarrays to ArrayOfArrays
	ArrayOfArrays.Add(New List(Of AnyClass))
Next
        	    
For j As Integer = 0 To 4   'Add 5 elements to the first subarray of ArrayOfArrays
	ArrayOfArrays(0).Add(New AnyClass)
Next

For j As Integer = 0 To 9   'Add 10 elements to the second subarray of ArrayOfArrays
	ArrayOfArrays(1).Add(New AnyClass)
Next

'To Use:
ArrayOfArrays(0)(0).str1 = "Hello World"
Debug.WriteLine(ArrayOfArrays(0)(0).str1)
 
Back
Top