I’m using VS2008.
Is the following OK to do the following VB.NET with a very simple class (see below)?
for each CurrentObject as MyObject in MyArray
'access current object
next
The “simple class”:
Class MyObject
public I as integer
end class
I seem to remember that something about needing iEnumerable, but my compiler isn’t complaining.
Edit: Clarification
This is completely fine.
Internally, .NET has your array MyArray implement IEnumerable, which is what the compiler looks for and uses when you use a foreach loop of this kind.
So you don’t need to do anything more.
Indeed, if MyArray is already declared as an array of MyObject you won’t need the cast to MyObject, so
will always work just fine as CurrentObject will always be of type MyObject.
You only need the cast if there’s nothing to tell .NET what type your array contains.