© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
7 replies
Sanne

✅ Array look if in right order?

I have this array:

int[] numbers = {1, 3, 4, 2, 6};
int[] numbers = {1, 3, 4, 2, 6};


After that array, I have this:

private void label2_Click(object sender, EventArgs e)
        {

            int scorestreet = 0;

            Array.Sort(numbers);

            bool isInSequence = numbers.SequenceEqual(Enumerable.Range(1, numbers.Count()));

            MessageBox.Show(isInSequence.ToString());
        }
private void label2_Click(object sender, EventArgs e)
        {

            int scorestreet = 0;

            Array.Sort(numbers);

            bool isInSequence = numbers.SequenceEqual(Enumerable.Range(1, numbers.Count()));

            MessageBox.Show(isInSequence.ToString());
        }


Currently it looks if it's in the right order '1 2 3 4 5' (It's not at the moment, so it'll return false.)

But how can I make it look if it's in the right order '1 2 3 4'? It keeps returning false because it looks at all numbers in the array, not only the first 4. I tried changing 'numbers.Count()' to 4, and I also tried 'numbers.Count() - 1' but those aren't working.
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

Similar Threads

✅ Does this styling code look right?
C#CC# / help
3y ago
❔ Formatting C# code in VSCode doesn't look right
C#CC# / help
3y ago
✅ return RedirectToAction("Index", new { orderId = ordervar });why dose this only show new orderhow
C#CC# / help
3y ago