NeuralJack Posted August 11, 2006 Posted August 11, 2006 (edited) [PLAIN]HashTable vs Jagged Array for an array of arrays[vb.net][/PLAIN] 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? Edited August 11, 2006 by NeuralJack Quote Currently Using: Visual Basic.Net 2005, .Net Framework 2.0
Administrators PlausiblyDamp Posted August 11, 2006 Administrators Posted August 11, 2006 As you are using .Net 2 then you might want to investigate generics as an alternative to both arrays / HashTables. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
NeuralJack Posted August 11, 2006 Author Posted August 11, 2006 Thanks PD , the generic class "List" seems to be perfect. As you are using .Net 2 then you might want to investigate generics as an alternative to both arrays / HashTables. Quote Currently Using: Visual Basic.Net 2005, .Net Framework 2.0
NeuralJack Posted August 11, 2006 Author Posted August 11, 2006 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: 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: 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. Quote Currently Using: Visual Basic.Net 2005, .Net Framework 2.0
NeuralJack Posted August 13, 2006 Author Posted August 13, 2006 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'. '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) Quote Currently Using: Visual Basic.Net 2005, .Net Framework 2.0
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.