Often when I’m programming, I’ll need to list a bunch of stuff and put commas between them. Like this:
1
|
|
Usually, this is what I, and most of my colleagues do:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
After reading Eric Lippert’s little article about the horrid-seeming problem of commas and lists, I noticed him mentioning the method
1
|
|
Needless to say, I went and tried it, and found that I could do the equivalent of the above, like this:
1 2 3 4 5 6 7 8 |
|
Its kinda amazing how after coding in C# for a good year now that I haven’t noticed the existence of such a method.
Okay, the lambda expression seems a bit messy with all the parens and all, but you get the idea. Still, its a lot better than writing a loop and having the evil “first” variable which kinda clutters the whole thing. Does anyone know an even better way of doing this?
Update: and for my answer to Eric’s next post:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|