Hi
So hab die Klasse nochmal leicht geändert, Property genommen statt ne Get und Set Methode. Muss auf Arbeit zu viel Java machen ^^Class ArrayBox
Class ArrayComparer
Implements IComparer(Of Integer)
Private dimension As Integer
Private indices As Integer()
Private box As ArrayBox
Private multiDimArray As Array
Sub New(ByVal multiDimArray As Array, ByVal realIndices As Integer(), _
ByVal dimension As Integer)
Me.multiDimArray = multiDimArray
Me.dimension = dimension
Me.indices = realIndices
End Sub
Public Function Compare(ByVal x As Integer, ByVal y As Integer) As _
Integer Implements IComparer(Of Integer).Compare
indices(dimension) = x
Dim xVal As IComparable = CType(multiDimArray.GetValue(indices), _
IComparable)
indices(dimension) = y
Dim yVal As IComparable = CType(multiDimArray.GetValue(indices), _
IComparable)
Return xVal.CompareTo(yVal)
End Function
End Class
Private multiDimArray As Array
Private Indices As Integer()()
Sub New(ByVal multiDimArray As Array)
Me.multiDimArray = multiDimArray
Indices = DirectCast(Array.CreateInstance(GetType(Integer()), _
multiDimArray.Rank), Integer()())
For i As Integer = 0 To Indices.Length - 1
Indices(i) = DirectCast(Array.CreateInstance(GetType(Integer), _
multiDimArray.GetLength(i)), Integer())
For j As Integer = 0 To Indices(i).Length - 1
Indices(i)(j) = j
Next
Next
End Sub
Default Property Value(ByVal indices As Integer()) As Object
Get
Return multiDimArray.GetValue(GetRealIndices(indices))
End Get
Set(ByVal value As Object)
multiDimArray.SetValue(value, GetRealIndices(indices))
End Set
End Property
Sub Sort(ByVal indices As Integer(), ByVal dimension As Integer)
Array.Sort(Me.Indices(dimension), New ArrayComparer(Me.multiDimArray, _
GetRealIndices(indices), dimension))
End Sub
Private Function GetRealIndices(ByVal indices As Integer()) As Integer()
Dim indis As Integer() = DirectCast(indices.Clone, Integer())
For i As Integer = 0 To indis.Length - 1
indis(i) = Me.Indices(i)(indis(i))
Next
Return indis
End Function
End Class Also Aufruf geht so:Dim box As New ArrayBox(myArray) Auf Werte zugreifen dann so (über Default Property Value):box(new Integer() {....}) = val Wichtig: Es wird zwar auf das Orginal-Array zugegriffen, aber es wird nicht wirklich sortiert. Der Zugriff wird nur umgeleitet. |