sort Array

  • Thread starter Thread starter Rado
  • Start date Start date
R

Rado

Hello.
In Vb.NEt I can You Function Array.sort(name)
But "name" must be only one dimension array.
How can I sort two dimension array.
For Exapmle:
Dim age(4,1)

Age (0,0)=Mark Age(0,1)=19
Age (1,0)=Larry Age(1,1)=25
Age (2,0)=Susan Age(2,1)=29
Age (3,0)=John Age(3,1)=32
Age (4,0)=Peter Age(4,1)=50

And I would like to short this array by age.
Thank You very much for answers.
 
Well, one way would be to create a Structure containing the two variables
such as

Structure Person
Dim age as Integer
Dim name as String
End Structure

Then create an array of these structures such as

Dim people() as Person

Then you can sort this one dimensional array using the sort routine by
providing a comparison routine that implements the IComparable interface to
determine how to sort the array. Take a look at the IComparable interface
documentation on MSDN for an example of a comparison routine.

http://msdn.microsoft.com/library/d...ref/html/frlrfsystemicomparableclasstopic.asp
 
Back
Top