Array.Clearメソッドでジャグ配列をクリアする場合は、ジャグ配列の1段目に格納されている配列がクリアされヌル参照(null/Nothing)の状態になります。 ジャグ配列に格納されている各配列はクリアされません。
Array.Clearメソッドで2段のジャグ配列をゼロクリアする
Imports System
Class Sample
Shared Sub Main()
' ジャグ配列に格納する配列
Dim arr1() As Integer = {0, 1, 2, 3, 4}
Dim arr2() As Integer = {5, 6, 7}
' 2段のジャグ配列
Dim jagged()() As Integer = { _
arr1, _
arr2 _
}
' ジャグ配列をクリア
Array.Clear(jagged, 0, jagged.Length)
Console.WriteLine("jagged(0) Is Nothing : {0}", jagged(0) Is Nothing)
Console.WriteLine("jagged(1) Is Nothing : {0}", jagged(1) Is Nothing)
For Each elem As Integer In arr1
Console.Write("{0}, ", elem)
Next
Console.WriteLine()
End Sub
End Class
実行結果
jagged(0) Is Nothing : True jagged(1) Is Nothing : True 0, 1, 2, 3, 4,