Does VB.net have a foreach function or equivalent for stepping through a list. ?
Yes.
For Each(var As Type in SomeEnumerableObject )
'blah blah blah
Next
The reason you often see VB code that uses IEnumerator
directly rather than For Each, is because the programmmer
got the code from Reflector's disassembly, which may not
know how to reverse-engineer the compiled code back to
the original source construct. That's possibly because VB's
For Each, and the C# foreach() are both compiler-provided
(and compiler specific) syntactic sugar, that compiles down
to IL code that manipulates the methods of the enumerator
directly.
I don't have any definitive conclusion that explains the
differences you see, but you might gain some insight into
what's going on, by looking at both of your functions in
Reflector, rendered as IL.
Does VB.net have a foreach function or equivalent for stepping through a list. ?
I saw some VB code this afternoon that used SymbolTableEnumerator
I've done some quick tests and it seems about 40% slower than foreach.
If thats so, I'm sorry
added; really, I am ! there MUST be a better way ...
though I s'pose its only a couple of milliseconds difference to itterate a decent layer list.
Command: LayerListTimer
Timer for 1000 iterations :
Total Time LayerList1 Enumerator <second>: 5.47726735744158
Total Time LayerList2 foreach <second>: 3.41111156322627