|
-
Sep 28th, 2008, 10:41 PM
#1
Thread Starter
Member
[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.
Last edited by rhijaen; Sep 28th, 2008 at 11:09 PM.
-
Sep 28th, 2008, 10:51 PM
#2
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)
-
Sep 28th, 2008, 11:09 PM
#3
Thread Starter
Member
Re: [2008] Sort 3 arrays at once
Thanks, worked perfectly.
-
Sep 28th, 2008, 11:20 PM
#4
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|