Bu döngüler için iç içe geçmiş olan
Not Bunun olabilir: bir dizi elemanları üzerinde ilerlerken her döngü için bir kullanırken, her yineleme oluşturulan tutucu gerçek dizi değerin bir kopyasıdır. Bu değerindeki değişiklikler orijinal diziye yansıtılmayacaktır. Bilgileri okumaktan başka bir şey yapmak isterseniz, doğrudan dizi elemanlarına hitap etmek için bir For döngüsü kullanmanız gerekecektir.
İki boyutlu bir dizi varsayarsak, aşağıdaki kod örneği, her boyuttaki her öğeye bir değer atayacaktır. Eğer Konrad Rudolph gibi pürüzlü dizide üzerinde döngü düşündüren edildi (Bu işlevsel daha yakından daha gevşek diğer dizi uygulamaları ile eşleşen istiyorsanız
Dim MasterIndex(5, 2) As String
For iOuter As Integer = MasterIndex.GetLowerBound(0) To MasterIndex.GetUpperBound(0)
'iOuter represents the first dimension
For iInner As Integer = MasterIndex.GetLowerBound(1) To MasterIndex.GetUpperBound(1)
'iInner represents the second dimension
MasterIndex(iOuter, iInner) = "This Isn't Nothing" 'Set the value
Next 'iInner
'If you are only interested in the first element you don't need the inner loop
MasterIndex(iOuter, 0) = "This is the first element in the second dimension"
Next 'iOuter
'MasterIndex is now filled completely
İsterseniz dinamik olarak her boyutta
tekrarlatacak .Rank
özelliğini kullanabilirsiniz PHP gibi yazılan diller) bu kadar gibi bu konuda gidebiliriz:
'This is a jagged array (array of arrays) populated with three arrays each with three elements
Dim JaggedIndex()() As String = {
New String() {"1", "2", "3"},
New String() {"1", "2", "3"},
New String() {"1", "2", "3"}
}
For Each aOuter As String() In JaggedIndex
'If you are only interested in the first element you don't need the inner for each loop
Dim sDesiredValue As String = aOuter(0) 'This is the first element in the inner array (second dimension)
For Each sElement As String In aOuter
Dim sCatch As String = sElement 'Assign the value of each element in the inner array to sCatch
sElement = "This Won't Stick" 'This will only hold value within the context of this loop iteration
Next 'sElement
Next 'aOuter
'JaggedIndex is still the same as when it was declared
Ben senin daha detaylı istek – JoshHetland