Back to questions
JuniorTheoryCommon
What does the program print?
List<int> nums = [3, 8, 1, 6];
var result = nums.Where(n => n > 2).Select(n => n * 10);
Console.WriteLine(string.Join(" ", result));30 80 60
- Expecting
3 8 6: despite its name,Selectdoes not pick items; it turns each one into the lambda's result, heren * 10. - Reading the chain in any order:
Whereruns first and filters the original numbers, andSelectgets only those that passed.
- What does the program print if
Selectcomes beforeWherein the chain? - How would you get the result as a
List<int>instead of a query?