0
Why Output is 2,4,6 please explain
var numbers = new int[] {1, 2, 3, 4,5,6}; foreach (var number in numbers) { if (numbers%2==0) { Console.WriteLine(number); } }
2 Answers
+ 5
% is modulus. That what is left over after a division. So if you do n%2==0 and the result is 0. The number is even.
0
This code outputs multiples of 2 in the range [1,6]