Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

C#: var filtered = (new int[]{1,2,3,4}).Where<int>( i => i%2 != 0 );


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 );


Alternatively:

    var filtered = new List<int>{1, 2, 3, 4}.FindAll(x => x % 2 == 0);




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: