Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8445131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:34:55+00:00 2026-06-10T09:34:55+00:00

I have a imprmented sort method for a colection in my code and today

  • 0

I have a imprmented sort method for a colection in my code and today i noticed something strange. When i tried to add new enum values to the enum the sort method crashed with this error.

Unable to sort because the IComparer.Compare() method returns inconsistent results. Either a value does not compare equal to itself, or one value repeatedly compared to another value yields different results. x: ”, x’s type: ‘Texture2D’, IComparer: ‘System.Array+FunctorComparer`1[Microsoft.Xna.Framework.Graphics.Texture2D]’.

This seems really strange seens the sort is in now way dependent on earlyer result and all it should do is sort after the index of the enum insteed of alfabatic order.

Here is the code.

    availableTiles.Sort(CompareTilesToEnum);

    private static int CompareTilesToEnum(Texture2D x, Texture2D y)
    {
        int xValue = (int) (Enum.Parse(typeof(TileTyp), x.Name, true));
        int yValue = (int) (Enum.Parse(typeof(TileTyp), y.Name, true));
        if (xValue > yValue)
        {
            return 1;
        }
        else
        {
            return -1;
        }
    }

    public enum TileTyp
    {
        Nothing = -1,
        Forest,
        Grass,
        GrassSandBottom,
        GrassSandLeft,
        GrassSandRight,
        GrassSandTop,
        Mounten,
        Sand,
        Snow,
        Water,
        GrassSandTopLeft,
        GrassSandAll,
        GrassSandBottomLeft,
        GrassSandBottomRightLeft,
        GrassSandBottomRightTop,
        GrassSandBottomTopLeft,
        GrassSandRightLeft,
        GrassSandRightTop,
        GrassSandRightTopLeft,
        GrassSandBottomRight,
        GrassSandBottomTop
    }

The values i added was

    GrassSandBottomRight,
    GrassSandBottomTop
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T09:34:57+00:00Added an answer on June 10, 2026 at 9:34 am

    Your comparison never returns 0 – even if the values are equal. Any reason you don’t just ask int.CompareTo to compare the values?

    private static int CompareTilesToEnum(Texture2D x, Texture2D y)
    {
        int xValue = (int) (Enum.Parse(typeof(TileTyp), x.Name, true));
        int yValue = (int) (Enum.Parse(typeof(TileTyp), y.Name, true));
        return xValue.CompareTo(yValue);
    }
    

    Simpler and more importantly, it should actually work 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What I have is something similar to this: //method being called by thread pool
I have implemented a sort of Repository class and it has has GetByID ,
I have a buffered grid on which I've implemented a local sort function (client
I have implemented correctly bump's api, and added this code: - (void) configureBump {
I have implemented a test method with Jersey to run on my Google AppEngine
I have implemented one matrix multiplication with boost::numeric::ublas::matrix (see my full, working boost code
I have a bit of .NET code that retrieves the results from an Oracle
If I have a list of elements I would like to sort, Java offers
I'm making a small rpg game, and have implemented a sort of observer design
I just have implemented a threaded version of the merge sort. ThreadedMerge.java : http://pastebin.com/5ZEvU6BV

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.