Dear, the question of the problem in the subject, here is the code:
class Program { public static void Main(string[] args) { int[] arr = new int[5]; Work ob = new Work(); ob.Go(arr); for(int i =0; i< arr.Length; i++) { Console.WriteLine(arr[i]); } Console.ReadLine(); } } class Work { int temp = 0; public void Go(int[] arr) { for(int i = 0; i < arr.Length; i++) { if(i == 0) { arr[i] = temp; continue; } if((i % 1) == 0) { arr[i] = (temp = temp + 2); } } } } The problem is solved correctly, but I do not understand why the correct result. Indeed, in the third step of the iteration, the array should be filled with zero (on the second index). That is, index 2 will NOT pass the parity check and the default constructor will fill it with zero. But this is not happening. Why?
tempvariable. Which was increased by2in the previous step (temp = temp + 2). - Dmitry D.