Home > Mobile >  Sorting a list of objects with VB.net
Sorting a list of objects with VB.net

Time:11-28

I am a novice at coding and whilst I have found examples on Stackoverflow that ought to address my situation, I struggle to understand the syntax and hence convert the example to my needs.

So I have a folder containing Outlook MSG files which I want process in 'Sent date' order. So what I'm trying to do is load them into a list and then sort them by date.

This may be a daft way to do it but I figured that if I create a 'class' containing filename and the date of each message, I could: add these to a list, sort it and then process the list.

So my class looks like this:

Class sMSG
    Public sFilename As String
    Public mDate As Date
End Class

My code to sort the list (modified from a stackoverflow example), looks like this:

            Dim ordered = From obj In SortedList
            OrderBy(obj.mdate Ascending)
            SortedList = ordered.ToList()

It generates the error: BC32017: Comma, ')', or a valid expression continuation expected.

I'm not familiar with this style of coding and can't work out where I am going wrong.

Any help would be appreciated but please be explain it in terms that a complete moron would understand as that just about sums me up at the moment!

CodePudding user response:

        SortedList = (From obj In SortedList Select obj Order By obj.mDate Ascending).ToList()
    'or
    SortedList = SortedList.OrderBy(Function(d) d.mDate)
  • Related