Home  |  Index  |  Dotnet4all Snippets  |  Submit resources
About  |  Mail us  
Dotnet4all Logo

  Implementing IComparable (Tuesday, December 21, 2004)




Found the following interesting discussion in the Newsgroups:

Implementing IComparable
by:Anonymous

Does anyone know if it's possible, and if so, how to implement a secondary comparison criteria?

Let's say we've got a collection of Person objects that we want sorted by LastName then by FirstName...
How would I construct a CompareTo function to accomplish this?

Thanks in advance!


 Reply:
by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])

 
\\Dim Result As Integer = x.LastName.CompareTo(y.LastName)
If Result = 0 Then
Result = x.FirstName.CompareTo(y.FirstName)
End If
Return Result
///

--
Herfried K. Wagner [MVP]


 Reply:
by:Anonymous

 BRILLIANT! Thanks a million!








0 Comments:

Post a Comment

 
Previous Posts
    - Known Bug - Possible Workaround??
    - Graph in VB.Net
    - Having problems migrating an ASP .net Page to ano...
    - VB.NET 2003 Standard Classes & DLL Creation
    - String concatenating for Dataset.compute method
    - Any VB/COM experts here??
    - The specified domain either does not exist or coul...
    - Measuring an angle
    - Unable to upgrade VB6 COM Dll to VB.Net
    - TypeConverter.CreateInstance-Method

Archives
    - 10/03/2004 - 10/10/2004
    - 10/10/2004 - 10/17/2004
    - 10/17/2004 - 10/24/2004
    - 10/24/2004 - 10/31/2004
    - 10/31/2004 - 11/07/2004
    - 11/21/2004 - 11/28/2004
    - 11/28/2004 - 12/05/2004
    - 12/05/2004 - 12/12/2004
    - 12/12/2004 - 12/19/2004
    - 12/19/2004 - 12/26/2004
    - 12/26/2004 - 01/02/2005
    - 01/23/2005 - 01/30/2005
    - 01/01/2006 - 01/08/2006
    - 09/24/2006 - 10/01/2006

Disclaimer & Terms of Use  | DotNet4All.Com concept & © 2004 - 2007 by  Zelders²  - Holland