3 ms·
C#: var filtered = (new int[]{1,2,3,4}).Where<int>( i => i%2 != 0 );
by uvTwitch 16y ago
C#: var filtered = (new int[]{1,2,3,4}).Where<int>( i => i%2 != 0 );
- lars 16y agoThis is what really shows the problem with Java.
- zackb 16y agoAnd C#...
- rayvega 16y agoAlternatively: var filtered = new List<int>{1, 2, 3, 4}.FindAll(x => x % 2 == 0);
- solutionyogi 16y agoAs 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. :)
- nrkn 16y agoHi 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 );