C# Loop Array Index Values back to Beginning of Array once out of Index

后端 未结 2 972
梦如初夏
梦如初夏 2021-01-20 05:25

I am looking to create a program like the following (c# btw):

int[] arr = new int[9]
//some code that puts values 1, 0, or 2 in each array element
for(int i          


        
2条回答
  •  迷失自我
    2021-01-20 05:46

    Use the modulo operator like this:

    if (arr[i] == arr[(i + 3) % arr.Length]) { return true; }
    

提交回复
热议问题