I know this has been well covered by others, but I needed this for my book, so here it is:
I know this has been well covered by others, but I needed this for my book, so here it is:
http://www.nickhodges.com/post/Enumerating-and-the-for%E2%80%A6in-Loop.aspx
http://www.nickhodges.com/post/Enumerating-and-the-for%E2%80%A6in-Loop.aspx
http://www.nickhodges.com/post/Enumerating-and-the-for%E2%80%A6in-Loop.aspx
http://www.nickhodges.com/post/Enumerating-and-the-for%E2%80%A6in-Loop.aspx
It looks like adding comment on your blog doesn't work. When I click "Save comment", it runs forever saying "Saving the comment..."
ReplyDeleteWell, the comment feature works with Chrome but doesn't work with IE9.
ReplyDeleteI would be actually ary of making everything enumerable, as it makes everything look like a nail to a convenient for-in hammer.
ReplyDeleteEnumeration is only good when order is not important, you're not mutation the collection (adding/removing), and bugs/errors aren't expected (since you don't have index nor path information about the object you're processing).
For anything more complex cursors are preferable (enumerators are the simplest form of cursors)
Eric Grange But if you got a cursor it's nice to have an enumerable wrapper for when you just want to read/modify each element.
ReplyDeleteAsbjørn Heid If you have a cursor you should probably always avoid the enumerable, as the cursor is debuggable easily, while the enumerable for-in loop isn't (not without dropping down to cpu view...)
ReplyDeleteEric Grange Not sure I understand, when debugging you could always trap the MoveNext, GetCurrent etc calls, if really needed. I must admit I haven't found a need once the wrapper is completed though. Though my wrappers are simple, so perhaps that's it :)
ReplyDeleteAsbjørn Heid This isn't for bugged enumerators, but when you have something that fails in whatever the loop is doing, and you want to know what object is failing (knowing it by its index, it position in the list, etc.) so you can diagnose directly when the exception occurs (rather than having to step through, place conditional breakpoints, etc.)
ReplyDeleteEric Grange Ok fair enough, the cursor based stuff I've wrapped doesn't really provide much more than the current element, so haven't seen the need. If it truly is an indexable collection or similar, then sure.
ReplyDeleteFrançois Piette Can you try the comments now? I think I have them working with IE, but I can never tell for sure. ;-)
ReplyDeleteFrançois Piette IE should be banned. I cannot believe how much time we waste trying to work our web applications around IE's "standards". We're actually considering telling clients that for non public-facing applications, we'll only support Chrome, FireFox, and Safari. If they insist on IE, they pay extra. Sorry for thread drift, but I just came off a late night of battling IE issues.
ReplyDeleteKevin --
ReplyDeleteCan you give comments-with-IE a look on my site? I implemented a fix recommended by the BlogEngine team.....
Just tried IE (9.0.8112.16421) from my W7 box and see the same problem as described by François Piette
ReplyDeleteGrrrrr.
ReplyDeleteI confirm the problem persists :-(
ReplyDeleteThat's weird, because I can add comments as you can probably see --
ReplyDeleteNick Hodges do you nean you can add comments using IE9? I can add comments using Chrome but not IE9. I tried from 2 different computers (Win7 and W2K8). Both fails.
ReplyDeleteI can with IE10 -- but I couldn't before I put in the fix. Great.
ReplyDelete