Re: Some notes on C# 3.0 (was RE: [DOTNET-CX] How to overload == for System.Double)
Alan Baljeu <[email protected]> Tue, 6 Feb 2007 10:50:19 -0500
| Newsgroups | gmane.comp.windows.devel.dotnet.cx |
|---|---|
| Message-ID | <09dd01c74a06$82494e90$1dc80ac6@CTI> |
> Sure here we go. This is what the compiler does consecutively:
>
> > IEnumerable<string> selectedWords =
> > from p in EinsteinQuote
> > where p.Equals("any") != true
> > select p;
>
> becomes (using lambda expressions)
>
> > IEnumerable<string> selectedWords =
> > EinsteinQuote.Where(p => p.Equals("any") != true).Select(p=>p);
Now this form makes sense! But as you say, the Select(Identity) call is pointless so it
could be dropped. Can I also write
from p in EQ where p.Equals("any") != true
?
> Which allows you to write something like this:
>
> string r = s.ToUpper().Reverse().Trim().PadLeft('*',
> 9).Substring(1,5);
>
> whereas in the past you'd have to write:
>
> string t = s.ToUpper();
> string r = MyExtensions.Reverse(t).Trim().PadLeft('*',
> 9).Substring(1,5);
>
> effectively breaking the convenient call chain.
Try:
string r = MyExtensions.Reverse(s.ToUpper())
.Trim().PadLeft('*', 9).Substring(1,5);
I do find it troubling that these extensions allow you to access Reverse without even naming
the class it is defined in. This seems to be a great source of potential name polution.
What's going to happen after several classes extend string?
===================================
This list is hosted by DevelopMentorĀ® http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com