2007/03/08(Thu) 12:56:35 編集(投稿者)
こんにちは
手抜きですが、私ならこのようにして
HashTableを継承したクラスにToArrayメソッドを持たせます。
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim table As New Hashtable()
With table
.Add("aa", New Item(1, 0))
.Add("bb", New Item(2, 1))
.Add("cc", New Item(3, 2))
.Add("dd", New Item(4, 3))
End With
Dim arr(table.Count - 1) As Object
Dim counter As Integer = 0
For Each obj As Object In table.Values
arr(counter) = DirectCast(obj, Item)
counter += 1
Next
Array.Sort(arr)
End Sub
End Class
Public Class Item
Implements IComparable
Private _index As Integer
Private _value As Object
Public Sub New(ByVal value As Object, ByVal index As Integer)
Me._index = index
Me._value = value
End Sub
Public ReadOnly Property Value() As Object
Get
Return _value
End Get
End Property
Public Function CompareTo(ByVal obj As Object) As Integer Implements System.IComparable.CompareTo
Dim other As Item = DirectCast(obj, Item)
Return Me._index - other._index
End Function
End Class