以下代码是从C#代码中删除的。我想知道代码中For .... To ...语句的重要性是什么?
Public Sub CopyFile(sourceFile As String, backupFile As String, overwrite As Boolean)
If String.IsNullOrEmpty(sourceFile) Then
Throw New ArgumentNullException("sourceFile")
End If
If String.IsNullOrEmpty(backupFile) Then
Throw New ArgumentNullException("backupFile")
End If
' According to MSDN Certain file attributes, Hidden and ReadOnly, can be combined. Other attributes, such as Normal, must be used alone.
If File.Exists(backupFile) Then
File.SetAttributes(backupFile, FileAttributes.Normal)
End If
' ????????
For index As Integer = 0 To 9
Try
File.Copy(sourceFile, backupFile, overwrite)
Exit Try
Catch ex As FileNotFoundException
Throw
Catch ex As Exception
If Not overwrite Then
Throw
End If
If index = 9 Then
Throw
End If
Thread.Sleep(1000)
End Try
Next
End Sub