In the old days, we’d write something like this:
view.Rows.Add("Type"); view.Rows.Add("Count"); view.Rows.Add("Whatever");
With C# 3.0 we can do this:
new string[] { "Type", "Count", "Whatever" } .ForEach(str => view.Rows.Add(str));
That is very cool syntatic sugar. Sure, this is not new news, but when you think about C# in the context of the new features available in 3.0, it really starts to feel a lot more like coding with JavaScript (which is a good thing).
josh says:
i’ve had many disagreements with mark twain, not the least of which is his being dead in times when his wit would be well applied. (random thought. got a quota ya know)
anyway, yeah c# 3.0 is cool. hoping to use it some time this year.
josh says:
..and now I see the quote at the bottom of the page is random too. thus my random comment has absolutely no context. yay.
Mischa Kroon says:
I’d have to say that for me it seems a step backward.
You save 1 line of code, and it doesn’t become clearer what the code does.
Exactly the opossite.
There might be other things in which it does benefit but for me this is a bad example.
brian says:
A lot of it is style, that’s for sure. It may be less “obvious” on quick glance, but has scalability benefits, and provides much greater usefulness for larger sets of repetitive operations. Imagine the same code above with eight “Rows.Add()”… The latter (with lambda expressions and such) focuses on the functionality and interaction with data, whereas the former is simply procedural.
The best part of it is each person gets to choose to do it however they want, and the result is the same. 🙂