Re:Why I absolutely love java
by uvTwitch on Tuesday February 08, 2011 @06:55PM
(#2195482)
C#: var filtered = (new int[]{1,2,3,4}).Where<int>( i => i%2 != 0 );
[ Parent
| on HN ]
Re:Why I absolutely love java
by solutionyogi on Tuesday February 08, 2011 @07:22PM
(#2195576)
As C# has some type inference, you can reduce it further:
var filtered = (new[] { 1, 2, 3, 4 }).Where(i => i % 2 != 0);
Not bad for a static language. :)
This is what really shows the problem with Java.
And C#...
Hi David :)
You can drop the parentheses, and int is inferred by the compiler:
var filtered = new[]{ 1, 2, 3, 4 }.Where( i => i % 2 != 0 );
Alternatively:
var filtered = Enumerable.Range( 1, 4 ).Where( i => i % 2 > 0 );