Re: How to sort a List (Of T)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steve Gerrard

    Re: How to sort a List (Of T)

    Göran Andersson wrote:
    >
    You just have to supply the Sort method with a Comparison:
    >
    oSection.Keys.S ort(delegate(Ke y x, Key y){ return
    string.Compare( x.Name, y.Name); })

    Not sure if that C# code will play in VB. :)

    I found this way to be reasonable:

    In class Key, add a shared function:

    Public Shared Function CompKeysByName( ByVal X As Key, ByVal Y As Key) As Integer
    Return X.Name.CompareT o(Y.Name)
    End Function

    Then for the sort, do

    oSection.Keys.S ort(AddressOf Key.CompKeysByN ame)




  • =?ISO-8859-1?Q?G=F6ran_Andersson?=

    #2
    Re: How to sort a List (Of T)

    Steve Gerrard wrote:
    Göran Andersson wrote:
    >You just have to supply the Sort method with a Comparison:
    >>
    >oSection.Keys. Sort(delegate(K ey x, Key y){ return
    >string.Compare (x.Name, y.Name); })
    >
    >
    Not sure if that C# code will play in VB. :)
    >
    I found this way to be reasonable:
    >
    In class Key, add a shared function:
    >
    Public Shared Function CompKeysByName( ByVal X As Key, ByVal Y As Key) As Integer
    Return X.Name.CompareT o(Y.Name)
    End Function
    >
    Then for the sort, do
    >
    oSection.Keys.S ort(AddressOf Key.CompKeysByN ame)
    >
    >
    Yes, you are right, I didn't check the language too carefully before
    posting. That would (almost) be the VB version of my code. :)

    --
    Göran Andersson
    _____
    Göran Anderssons privata hemsida.

    Comment

    Working...