每当我尝试输出数组时,数组都会继续输出 "System.Int32[ ]" - 有人知道为什么吗?
array keeps on outputting "System.Int32[ ]" whenever I try to output an array - anyone know why?
For numberOfRunsCompleted As Integer = 0 To arrayToSort.Length
For valueWithinArray As Integer = 0 To arrayToSort.Length - 2
If arrayToSort(arrayValue) > arrayToSort(arrayValue + 1) Then
Dim tempStorage As Integer = arrayToSort(arrayValue)
arrayToSort(arrayValue) = arrayToSort(arrayValue + 1)
arrayToSort(arrayValue + 1) = tempStorage
End If
Next
Next
数组声明为arrayToSort(7)
,是从 9 到 2 的整数。
我将您的变量 valueWithinArray
的名称更改为 index
。它实际上不是数组中的值,它是元素的索引。您在真正需要 valueWithinArray
(现在称为 index
)的地方引入了另一个未声明的变量 (arrayValue
)。
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim arrayToSort() As Integer = {6, 8, 7, 2, 9, 4, 5, 3}
For numberOfRunsCompleted As Integer = 0 To arrayToSort.Length
For index As Integer = 0 To arrayToSort.Length - 2
If arrayToSort(index) > arrayToSort(index + 1) Then
Dim tempStorage As Integer = arrayToSort(index)
arrayToSort(index) = arrayToSort(index + 1)
arrayToSort(index + 1) = tempStorage
End If
Next
Next
For Each i In arrayToSort
Debug.Print(i.ToString)
Next
End Sub
这是一个很好的学习练习,但为了节省一些打字时间...
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim arrayToSort() As Integer = {9, 8, 7, 6, 5, 4, 3, 2}
Array.Sort(arrayToSort)
For Each i In arrayToSort
Debug.Print(i.ToString)
Next
End Sub
结果将立即显示在Window。
For numberOfRunsCompleted As Integer = 0 To arrayToSort.Length
For valueWithinArray As Integer = 0 To arrayToSort.Length - 2
If arrayToSort(arrayValue) > arrayToSort(arrayValue + 1) Then
Dim tempStorage As Integer = arrayToSort(arrayValue)
arrayToSort(arrayValue) = arrayToSort(arrayValue + 1)
arrayToSort(arrayValue + 1) = tempStorage
End If
Next
Next
数组声明为arrayToSort(7)
,是从 9 到 2 的整数。
我将您的变量 valueWithinArray
的名称更改为 index
。它实际上不是数组中的值,它是元素的索引。您在真正需要 valueWithinArray
(现在称为 index
)的地方引入了另一个未声明的变量 (arrayValue
)。
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim arrayToSort() As Integer = {6, 8, 7, 2, 9, 4, 5, 3}
For numberOfRunsCompleted As Integer = 0 To arrayToSort.Length
For index As Integer = 0 To arrayToSort.Length - 2
If arrayToSort(index) > arrayToSort(index + 1) Then
Dim tempStorage As Integer = arrayToSort(index)
arrayToSort(index) = arrayToSort(index + 1)
arrayToSort(index + 1) = tempStorage
End If
Next
Next
For Each i In arrayToSort
Debug.Print(i.ToString)
Next
End Sub
这是一个很好的学习练习,但为了节省一些打字时间...
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim arrayToSort() As Integer = {9, 8, 7, 6, 5, 4, 3, 2}
Array.Sort(arrayToSort)
For Each i In arrayToSort
Debug.Print(i.ToString)
Next
End Sub
结果将立即显示在Window。