System.Array.Sort on a Class Array

S

ShrimpBoy

Hi!

I have an array filled with a class that have some properties...

I noticed the Sort method but I don't know how to use it to sort my items...

I have an array filled with object of a class like this...

Person.FirstName
Person.LastName
Person.Special
Person.Comment

I want to sort them by their FirstName...

Is their a way to do it?

Thanks a lot!

Fred
 
H

Henning Krause [MVP - Exchange]

Hello,

you can either implement IComparable on your Person object, or call the Sort
method which takes either an IComparer or the Comparison delegate.

In either of those scenarios you are dealing with two instances of type
Person where you can compare them according to your rules (e.g. Firstname).

Kind regards,
Henning
 
S

ShrimpBoy

Hi!

I looked at System.Collections.IComparer

It has a Compare method but I really don't know how to use it to do what I
need...

Dim Comparer As System.Collections.IComparer
Comparer(Person(1).FirstName, Person(2).FirstName)
System.Array.Sort(Person, Comparer)

It means I have to have 2 items or more in my array, I'm really not sure how
to use it..:S

Can you help me?

Thanks!

Fred
 
J

Jack Jackson

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