I just used LINQ for the first time ever in code. Pretty exciting. For me, it doesn’t get much better than transforming some mundane 6 liner into an elegant one liner.
This…
int count = 0; foreach (string email in this.emails) { if (email.EndsWith("@mydomain.com")) count++; } return count;
becomes this…
return this.emails.Count(email => email.EndsWith("@mydomain.com"));
In some weird kind of way, I feel like an emo Ruby developer. Maybe I’ll start wearing some tighter clothes.
Wow, you’re lame.
I personally like the 4 liner. It reads.
The ‘optimized’ code doesn’t at all become immediately clear. Namely the ‘email’ variable was never declared and that really screws with my head. Then again, I’ve been screwing around with perl, so nothing is ever immediately clear (and that is usually an invariant).