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

Sort pair values using numeric column

P: n/a
I would like to keep track of pairs of values, like this:

Apple 50
Pear 100
Banana 30

I would like to keep this data sorted using the number column, and not
the text column.

So, I need this:

Pear 100
Apple 50
Banana 30

Please can someone recommend a good .NET framework "structure" that
would help me achieve this.

TIA,
-dnw.
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Take a look athe System.Collections.SortedList class. Add the number as the
key and the string as the item and you should have your items sorted.

eg. Dim oSortedList as New SortedList
oSortedList.Add(50, "Apple")
oSortedList.Add(100, "Pear"), etc

hope this helps..
Imran.

"Dot net work" <do***@hotmail.com> wrote in message
news:77**************************@posting.google.c om...
I would like to keep track of pairs of values, like this:

Apple 50
Pear 100
Banana 30

I would like to keep this data sorted using the number column, and not
the text column.

So, I need this:

Pear 100
Apple 50
Banana 30

Please can someone recommend a good .NET framework "structure" that
would help me achieve this.

TIA,
-dnw.

Nov 21 '05 #2

P: n/a
Thanks a lot.

As a finishing touch, I added the following:

'Make a comparer class that can see if an integer is greater or smaller
than another integer...

Private Class IntComparer
Implements IComparer

Public Function Compare(ByVal x As Object, ByVal y As Object) As
Integer Implements System.Collections.IComparer.Compare
Dim x1 As Integer
Dim x2 As Integer

x1 = Convert.ToInt32(x)
x2 = Convert.ToInt32(y)

If x1 < x2 Then Return 1 Else Return -1
End Function
End Class

'Next, make a sorted list, and use the above comparer class.

Dim oSL As New SortedList(New IntComparer())

'Then, in this particular case, your items are sorted with the highest
integer at the top (which is what I need)

So, if you have

50 Apple
100 Pear

Your list is sorted as:

100 Pear
50 Apple

Thanks, dnw.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.