Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27514

VS 2012 Find Smallest TimeSpan in List

$
0
0
In Visual Basic.net, what is the best way to find the smallest TimeSpan value in a list of TimeSpans as well as the Index of the TimeSpan in the List?
I know that I can sort the List, but how do I find the Index of the Item in the List?

Here is my current code:

Code:

    Public Function CalculateClosestScheduleStart(Schedule As Schedule) As TimeSpan
        Dim TimeSpanList As New List(Of TimeSpan)
        Dim Seconds As Double
        Dim TimeSpan As TimeSpan
        For x = 0 To Schedule.ScheduleItemList.Count - 1
            Seconds = DateDiff(DateInterval.Second, Now, Schedule.ScheduleItemList(x).StartTime)
            TimeSpan = TimeSpan.FromSeconds(Seconds)
            TimeSpanList.Add(TimeSpan)
        Next

        For x = 0 To TimeSpanList.Count - 1
            MsgBox(TimeSpanList(x).ToString)
        Next

    End Function


Viewing all articles
Browse latest Browse all 27514

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>