我有这个简单的代码:
Public Class Form1
Dim strFriends(4) As String
Private Sub ArrayElement_Click(sender As Object, e As EventArgs) Handles ArrayElement.Click
ClearList()
'Try
For Each item As String In strFriends
lstFriends.Items.Add(item)
Next
'Catch
'End Try
End Sub
Private Sub ClearList()
lstFriends.Items.Clear()
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
strFriends(0) = "tom"
strFriends(1) = "kate"
strFriends(2) = "bill"
strFriends(3) = "harry"
End Sub
结束类
如果删除了 try-catch,我知道System.ArgumentNullException
是否必须使用 try catch 块才能使用 For Each?