sorting an iList help

J

jvcoach23

I'm trying to figure out how to sort an iList in vb.net. Say i have a
collection that looks like
Private mvcLastName As String = Nothing
Private mvcFirstName As String = Nothing
Public Property LastName() As String
Get
Return mvcLastName
End Get
Set(ByVal pvalue As String)
mvcLastName = pvalue
End Set
End Property
Public Property FirstName() As String
Get
Return mvcFirstName
End Get
Set(ByVal pvalue As String)
mvcFirstName = pvalue
End Set
End Property

I'd like to know how to sort it by the property firstname or lastname and
either asc or desc. I've been looking around... but not able to get it
figured out.

thanks
hope someone can lend a hand
 
C

Cor Ligthert[MVP]

Hi,

You can start here,

http://msdn.microsoft.com/en-us/library/system.collections.collectionbase.aspx

As it is about sorting then it is mostly easier to use a class build for
data.

For sorting anything else you need to implement the Icomparer interface
http://msdn.microsoft.com/en-us/library/system.collections.icomparer.aspx

Beside that you can use as well a generic list and generic Icomparer class,
because your properties have to be used as object in the non generic lists.

Sorting is something I don't like in Net as it is done in my idea in an
elite way.
This is especially when it is about more value types in one sort. (For you
it is not so difficult as you have a only strings)

A better place to ask this question is however

microsoft.public.dotnet.languages.vb

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top