How to search In a Structure ?
-
Before I go crazy on this I was wondering if somebody could point me in the right direction :-) I was trying to use a structure to store "datasets" Anyway: Creating / populating the structure seems straight forward
Public Structure Test_Structure
Public Name As String
Public MapTo As String
Public Description As String
'......
'....
End StructureDim TEST(10) as Test_Structure
Test(0).Name = "FirstName"
Test(1).Name= "SecondNameBut How do I now search / get the index for the Dataset containing the .name "FirstName" Should I use a Hashtable to store the index ???? Thanks georg
-
Before I go crazy on this I was wondering if somebody could point me in the right direction :-) I was trying to use a structure to store "datasets" Anyway: Creating / populating the structure seems straight forward
Public Structure Test_Structure
Public Name As String
Public MapTo As String
Public Description As String
'......
'....
End StructureDim TEST(10) as Test_Structure
Test(0).Name = "FirstName"
Test(1).Name= "SecondNameBut How do I now search / get the index for the Dataset containing the .name "FirstName" Should I use a Hashtable to store the index ???? Thanks georg
You would use foreach to iterate over your array and check each item for the value you want.
Christian Graus Driven to the arms of OSX by Vista.
-
You would use foreach to iterate over your array and check each item for the value you want.
Christian Graus Driven to the arms of OSX by Vista.
Well if that's the "only" way, a Hashtable will be a lot faster I just can not belive there is not another way of indexing a Structure . One would think that indexing / searching is probabaly one of the most required tasks to be performe with a structure - But I might be wrong :-) Georg
-
Well if that's the "only" way, a Hashtable will be a lot faster I just can not belive there is not another way of indexing a Structure . One would think that indexing / searching is probabaly one of the most required tasks to be performe with a structure - But I might be wrong :-) Georg
Well a structure doesn't automatically build indexes into all it's data, imagine how wasteful that would be if it did that even when not required. Yes, a hashtable would be faster.
Christian Graus Driven to the arms of OSX by Vista.
-
Before I go crazy on this I was wondering if somebody could point me in the right direction :-) I was trying to use a structure to store "datasets" Anyway: Creating / populating the structure seems straight forward
Public Structure Test_Structure
Public Name As String
Public MapTo As String
Public Description As String
'......
'....
End StructureDim TEST(10) as Test_Structure
Test(0).Name = "FirstName"
Test(1).Name= "SecondNameBut How do I now search / get the index for the Dataset containing the .name "FirstName" Should I use a Hashtable to store the index ???? Thanks georg
First of all, you should not use a structure for this, you should use a class. A structure should not be larger than 16 bytes, and you break this if you have more than four string references. Also structures are tricker than classes to implement correctly. If you want a fast lookup for a field you can create a Dictionary with the field as key and the object as value.
Despite everything, the person most likely to be fooling you next is yourself.