I am playing with the new stuff of C#3.0 and I have this code (mostly taken from MSDN) but I can only get true,false,true… and not the real value :
int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 }; var oddNumbers = numbers.Select(n => n % 2 == 1); Console.WriteLine('Numbers < 5:'); foreach (var x in oddNumbers) { Console.WriteLine(x); }
How can I fix that to show the list of integer?
Change your ‘Select’ to a ‘Where’
The ‘Select’ method is creating a new list of the lambda result for each element (true/false). The ‘Where’ method is filtering based on the lambda.
In C#, you could also use this syntax, which you may find clearer:
which the compiler translates to: