9951 explained code solutions for 126 technologies


c#How to select all even numbers from a list


Enumerable.Range(1,20).Where(n => n % 2 == 0);ctrl + c
Enumerable.Range(1,20)

get an enumerable list populated with integers from 1 to 20

.Where

select all integers from that list where a condition is applied by an arrow function

n => n % 2 == 0

arrow function used to determine whether the number n tested has modulo % of zero when divided by 2