我对编码相当陌生。我正在编写 Visual Basic 教程,但我不理解代码中的一行。下面是代码。
Public Class Form1
Private Sub lstData_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lstData.SelectedIndexChanged
Dim strName As String
Dim strFavoriteColor As String
strName = lstData.Items(lstData.SelectedIndex).ToString
Select Case strName
Case "Bryan"
strFavoriteColor = "Madras Yellow"
Case "Ashley"
strFavoriteColor = "Sea Blue"
Case "Jenifer"
strFavoriteColor = "Morning Mist"
Case "Eddie"
strFavoriteColor = "Passionate Purple"
Case "Katelyn"
strFavoriteColor = "Red"
End Select
MessageBox.Show(strName & "'s favorite color is " & strFavoriteColor, "Select Demo")
End Sub
End Class
我不明白的行是strName = lstData.Items(lstData.SelectedIndex).ToString
我不知道.Items的意义是什么。我也无法理解括号内的代码及其用途。
我找到的最接近答案的是以下网站。我希望有人能以更容易理解的方式向我解释。