© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
62 replies
samisaskinnyqueen

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;
    }
}
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
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements
Next page

Similar Threads

Simple help trying to understand this error and how to fix it
C#CC# / help
7mo ago
error CS0506. How to fix?
C#CC# / help
2y ago
Error idk how to fix
C#CC# / help
3y ago
❔ Error idk how to fix
C#CC# / help
3y ago