<je**********@gmail.comwrote in message
news:e2**********************************@h11g2000 prf.googlegroups.com...
Hello:
I was running some tests today and found an interesting result. I have
a large library where half the methods work on IEnumerable<T>
(Iterators similar to LINQ), and another that works on List<T>, using
indices to overwrite values.
ok.
>
I wanted to see which performed better overall (I guessed wrong). What
surprised me what that a well-written Iterator typically ran faster
(usually generating a new IEnumerable<U>) than a similar method that
just overwrites a List<T>.
Good for you.
But what is 'faster'?
Is performance a problem for you?
>
Does anyone have a good explanation for why this is true?
I have not.
Is it just a fluke on my part? And what does the community say about using
one over
the other?
I say use 'foreach' over 'for'.
Not because one is faster or not,
but just to get rid of the
'i <= list.Length' bugs.
Also it looks nicer. Much more readable.
Also with typing foreach and press tab, you can do a iterator very quickly.
With the common snippet over foreach, with the old snippet started with
'var',
I just had to write my own foreach-snippet, 'fe' that skips that first step.
Don't need to tab through 'var' with my snippet. 'var' is just fine for me
=)
I honestly think there is something beautiful about
Iterators and would like to use them more often than not.
I honsestly also think they are beautiful. May have to do something with
that I actaully have to maintain other peoples code!? =)
The for(init; expression; iter) is HighTech from the -70ies (60ies?). - Move
along folks, there is nothing to see here.. move along...
>
Thanks for your input,
Use foreach whenever you can.
And Never, Never and NEVER, do a myList.ForEach(lambda =lambda.whatever
== 'something');
... that is just plain ugly!
foreach is your friend!
Travis
Happy Coding
- Michael Starberg