I have a List(Of SomeObject)
that I enumerate over using a For Each
loop. This SomeObject
contains a Property that references another Object, as such
Class SomeObject
Public Property Another As AnotherObject
Get
Return _another
End Get
Set (byval value as Integer)
_another = value
End Set
End Property
dim _another As New AnotherObject()
End Class
The question I have is whether updating AnotherObject property of SomeObject is valid within a For Each loop.
As such
Dim newanother As New AnotherObject()
For Each el As SomeObject in myobjects
el.Another = newanother
Next
Is this valid? If not, what is a valid way to d开发者_StackOverflow中文版o it? (ordinary for loop perhaps?)
you're just changing the value of a property that is correct!!!, you can doit inside a cycle scope or not, beeing your proprty type a object or a system type.
what you cannot do, is change the collection inside the iteration scope!
精彩评论