Saving pairs in memory

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi

I have a list of value pairs as below;

Section Name Section Type
A1111 Z9999
B2222 Y8888
C3333 X7777

What is a good intuitive way to store this information in memory? I was
thinking a two-dimensional array of strings, is there a better way?

Thanks

Regards
 
Hi

I have a list of value pairs as below;

Section Name Section Type
A1111 Z9999
B2222 Y8888
C3333 X7777

What is a good intuitive way to store this information in memory? I was
thinking a two-dimensional array of strings, is there a better way?

Will you need to look up a value from a key? If so perhaps a hashtable?
 
John said:
Hi

I have a list of value pairs as below;

Section Name Section Type
A1111 Z9999
B2222 Y8888
C3333 X7777

What is a good intuitive way to store this information in memory? I was
thinking a two-dimensional array of strings, is there a better way?

Thanks

Simplest way is with two parallel one-dimensional arrays.
Another way is as an array of structures.
I also liked Jeff's solution.
His question has merit - how will you be accessing the elements?
 
John,

For versions behind 2003

\\\
........................
Private Sub Routine()
Dim myPairs As New List(Of Pairs)
myPairs(0).First = "A1111"
myPairs(0).Second = " Z9999"
End Sub
End Class
Class Pairs
Private mFirst As String
Private mSecond As String
Public Property First() As String
Get
Return mFirst
End Get
Set(ByVal value As String)
mFirst = value
End Set
End Property
Public Property Second() As String
Get
Return mSecond
End Get
Set(ByVal value As String)
mSecond = value
End Set
End Property
End Class
///

Cor
 
Hi

I have a list of value pairs as below;

Section Name Section Type
A1111 Z9999
B2222 Y8888
C3333 X7777

What is a good intuitive way to store this information in memory? I was
thinking a two-dimensional array of strings, is there a better way?


Generic Dictionary or a hashtable.
 
Simplest way is with two parallel one-dimensional arrays.

With hashtables and dictionary... it's a bit amateurish to use two
parallel arrays.
Another way is as an array of structures.
I also liked Jeff's solution.
His question has merit - how will you be accessing the elements?

Hashtable("SectionName") = Type

A generic dictionary can store different data types too.

Or, you could create an array of custom objects which store SectionName
/ Section Type.
 
Back
Top