[RESOLVED] [2008] Sort 3 arrays at once
I think I need to use a bubble sort or something of the like.
Basically I need to sort a string array and have to integer arrays get sorted with it.
I would use Array.Sort(myArray) but that would sort them all individually.
Say I have
3 4 bob
2 9 stacey
9 1 max
I need this to be
3 4 bob
9 1 max
2 9 stacey
So the string is sorted alphabetically A to Z and the integers go with it.
Thanks for any help and code.
Re: [2008] Sort 3 arrays at once
You could write your own routine to do it but, as long as you don't mind sorting the strings twice, you can do it with Array.Sort:
vb.net Code:
Dim strings1 As String() = {"bob", "stacey", "max"}
Dim integers1 As Integer() = {3, 2, 9}
Dim integers2 As Integer() = {4, 9, 1}
Dim strings2 As String() = DirectCast(strings1.Clone(), String())
Array.Sort(strings1, integers1)
Array.Sort(strings2, integers2)
Re: [2008] Sort 3 arrays at once
Thanks, worked perfectly.
Re: [RESOLVED] [2008] Sort 3 arrays at once
Having said all of that, if possible it would be better to, rather than using three concurrent arrays, define a class or structure that has three properties: one String and two Integers. You can then have one array of that type and then sort it by the String property, which will inherently sort the Integers. Concurrent arrays are to be avoided in this day and age if possible.