How to fix a simple (hopefully) error?

I am doing a leetcode solution, and I have this so far:
public class Solution {
    public int HeightChecker(int[] heights) {
        int[] correctOrder = [];
        int amountWrong = 0;
        foreach(int i in heights) { 
            int iter = i;
            while (iter <= heights.Length){
                iter++;
                if (heights[i] < heights[iter]) {
                    int curr = heights[iter-1];
                   correctOrder[i] = correctOrder[heights[iter-1]];
                   heights[iter] = curr;
                }
            }
        }
        foreach(int i in heights) {
            if(heights[i] != correctOrder[i]){
                amountWrong++;
            }
        }
        return amountWrong;
    }
}

I am getting this error
image.png
Was this page helpful?