Hello my fellow Daniwebers!
I am having some problems wrapping my head around the task sorting a List(Of CustomType)
I have a list containing a custom class.
The class contains Two DateTime objects, Start and End.
I am trying to sort the list descending so that the shortest timespan will be on the bottom of the list.
I am unsure how to write the function that returns the value to sort.
I have read Microsoft's documentation here and, as all ways, I am more confused after reading it than I was before I began.
This is what I have deducted from the article:
lstType.Sort(Address SortMyList) Private Function SortMyList(ByVal x As Type, Byval y As Type) As Type Try Dim tsX As TimeSpan = x.dEnd.Subtract(x.dStart) Dim tsY As TimeSpan = y.dEnd.Subtract(y.dStart) If tsX > tsY Then Return x Else Return y End If Catch ex As Exception MsgBox("Exception from:" & ex.Source & vbcrlf & ex.Message & vbcrlf & ex.StackTrace.ToString) 'Used just to break execution Throw New NullReferenceException("") End Try End Function
Would this logic be correct?