【发布时间】:2012-04-27 09:03:48
【问题描述】:
我想知道在其中使用 For Each 循环时字符串数组的行为。考虑以下代码:
Dim StringArray(499) As String
'fill in each element with random string
Dim count As Int32
Dim current As String
For Each current in StringArray
'do something with current
count = count + 1
If count = 10
Exit For
End If
Next
're-enter the StringArray again
count = 0
For Each current in StringArray
'do something with current
count = count + 1
If count = 10
Exit For
End If
Next
如上面的代码所示,如果我需要使用 For Each 循环 访问 StringArray 两次,那么 StringArray 中的 ALL 元素是否会被加载两次,即使我在每个 For Each 循环 中只使用 10 个元素?从性能的角度来看,是否建议使用字符串数组作为数据结构来存储需要多次访问的字符串列表,例如在一个方法中访问 20 次?
【问题讨论】:
-
快速提问:“将被加载两次”你说的加载是什么意思?从哪里加载?
标签: .net vb.net arrays string foreach