这里有三种方法来做到这一点,把它放在一个控制台程序来测试它。一个为每个循环使用一个,一个使用for循环索引,一个使用linq查询。我创建了数组,并在其中放入了一些日期,然后将这些日期与DateTime.Now()进行了比较。
Dim dateList As DateTime() = {"1/1/2016", "1/15/2016", "1/31/2016", "2/15/2016"}
' For each loop
For Each d As DateTime In dateList
If d > DateTime.Now Then
Console.WriteLine(d.ToString())
End If
Next
' Loop by index
For x As Integer = 0 To dateList.Count - 1
If dateList(x) > DateTime.Now Then
Console.WriteLine(dateList(x).ToString())
End If
Next
' Linq Query
Dim results = From d In dateList Where d > DateTime.Now()
For Each d As DateTime In results
Console.WriteLine(d.ToString())
Next
Console.ReadKey()