vb.net显示最早的日期

时间:2017-06-04 06:47:13

标签: vb.net data-conversion

Book Collection作为介绍类的编码项目,需要显示最早的印刷年份。它最初显示但不会写入文件,因为我试图从字符串转换为整数。正在使用的代码:

Private Sub findOldest()
    Dim oldest As Integer = 4000
    Dim printDate As Integer
    For index As Integer = 2 To count * 4 - 1 Step 4
        printDate = CInt(bookData(index))
        If oldest > printDate Then
            oldest = printDate
        End If
    Next
    lblOldestBook.Text = CStr(oldest)
End Sub

1 个答案:

答案 0 :(得分:0)

您可以使用Linq返回最早的日期。至于写入.Text属性,您可以使用.ToString()将对象表示为字符串。

Dim MinDate = (From d In bookData).Min() 'untested!

lblOldestBook.Text = oldest.ToString()