By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,299 Members | 1,054 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,299 IT Pros & Developers. It's quick & easy.

Sorting a two-dimensional array

P: n/a
How do you sort a 2D array?

Dim myArray(10000, 9) As String

myArray contains 10000 records with 9 fields. I want to sort on the
Ninth field.
I want to be able to use the sort method, but how?

myArray.sort( ?, ?)
Thanks,
Moondog

Aug 7 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Moondog,

I wished to that there was a simple sort method, however it does not exist
in dotNet.

You have to create everytime new a sort method by using IComparable.
http://msdn2.microsoft.com/en-us/lib...omparable.aspx

If you say that it is an ommission, than we agree.

Cor
"moondog" <di****@verizon.netschreef in bericht
news:11**********************@q3g2000prf.googlegro ups.com...
How do you sort a 2D array?

Dim myArray(10000, 9) As String

myArray contains 10000 records with 9 fields. I want to sort on the
Ninth field.
I want to be able to use the sort method, but how?

myArray.sort( ?, ?)
Thanks,
Moondog
Aug 7 '07 #2

P: n/a
Hi Moondog,

The Sort method only works on single dimension arrays. Rather than using a
two dimensional array, you could use a jagged array, e.g:

Dim myArray(1000)() As String

' populate the array, ensuring there are 0 to 9 items in each slot
' the sort
Array.Sort(s, New Comparison(Of String())(AddressOf JaggedArrayComparer))

Private Function JaggedArrayComparer(ByVal item1 As String(), ByVal item2
As String()) As Int32
Return item1(9).CompareTo(item2(9))
End Function
Regards,

Bill.

"moondog" <di****@verizon.netwrote in message
news:11**********************@q3g2000prf.googlegro ups.com...
How do you sort a 2D array?

Dim myArray(10000, 9) As String

myArray contains 10000 records with 9 fields. I want to sort on the
Ninth field.
I want to be able to use the sort method, but how?

myArray.sort( ?, ?)
Thanks,
Moondog
Aug 7 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.