在下面的代碼中,我在行If (Not hash.Add(Numbers(Num))) Then
上收到以下錯誤類型'Integer'的值無法轉換爲'System.Array' 。我究竟做錯了什麼?VB.NET:無法將類型'Integer'的值轉換爲'System.Array'
Module Module1
Sub Main()
Dim array() As Integer = {5, 10, 12, 8, 8, 14}
' Pass array as argument.
Console.WriteLine(findDup(array))
End Sub
Function findDup(ByVal Numbers() As Integer) As Integer
Dim hash As HashSet(Of Array)
For Each Num In Numbers
If (Not hash.Add(Numbers(Num))) Then
Return (Num)
End If
Next
End Function
End Module
除了當前的錯誤(這@shahkalpesh已經回答了),這是不可能的,你要使用'號(NUM)'在調用'Add',因爲'Num'已經是一個值提取來自'Numbers'數組。 –