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 3489444
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:23:47+00:00 2026-05-18T11:23:47+00:00

You can do >, <, ==, etc. comparisons between sbyte and byte, int, uint,

  • 0

You can do >, <, ==, etc. comparisons between sbyte and byte, int, uint, short, ushort, long, double, and float. But not ulong.

My brain is exploding. Can anyone explain why sbyte can be compared to uint but not ulong?

public bool sbyte_ulong_compare(sbyte x, ulong y)
{
    return x < y;  // compiler error CS0019
}

Also, using unchecked doesn’t make things work any better. Brain melting.

Another edit. This works:

public bool sbyte_ulong_compare(sbyte x, ulong y)
{   
    //
    // returns x < y
    //
    if (x < 0)
        return true;

    if (y > 127)
        return true;

    return ((long)x < (long)y);
}
  • 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-05-18T11:23:48+00:00Added an answer on May 18, 2026 at 11:23 am

    dthorpe and Jon’s answers are close but not quite correct.

    The correct reasoning is as follows.

    The specification states:

    For an operation of the form x op y,
    where op is a comparison operator,
    overload resolution is
    applied to select a specific operator
    implementation.

    OK, what are the operator implementations that overload resolution has to work with? They are:

    bool operator <(int x, int y);
    bool operator <(uint x, uint y);
    bool operator <(long x, long y);
    bool operator <(ulong x, ulong y);
    bool operator <(float x, float y);
    bool operator <(double x, double y);
    bool operator <(decimal x, decimal y);
    

    Plus the enum less-than operator for all enumerated types, plus the lifted-to-nullable versions of each of the foregoing.

    Overload resolution must first eliminate inapplicable operators, and then from the remaining set of applicable operators, determine the best operator.

    The int, uint, long and enum operators (and their lifted forms) are all eliminated because ulong does not implicitly convert to those types.

    The uint and ulong operators (and their lifted forms) are all eliminated because sbyte does not implicitly convert to those types.

    That leaves

    bool operator <(float x, float y);
    bool operator <(double x, double y);
    bool operator <(decimal x, decimal y);
    

    and their lifted forms. We must now determine the best operator from those six.

    What do we mean by “best”? When comparing two operators, the one with the more specific operand types is the better one. By “more specific” I mean that “Tiger” is more specific than “Animal” because all Tigers are convertible to Animal but not all Animals are convertible to Tiger.

    Clearly the unlifted forms are better than all of the corresponding lifted forms. A non-nullable type is more specific than its corresponding nullable type because a non-nullable type is always convertible to its nullable type, but not vice-versa. We can eliminate the lifted forms.

    That leaves three. Which of those three is the best?

    float is more specific than double. Every float is convertible to double, but not every double is convertible to float. Therefore double is eliminated. That leaves two.

    bool operator <(float x, float y);
    bool operator <(decimal x, decimal y);
    

    Which of these is the best? There is no implicit conversion from float to decimal. There is no implicit conversion from decimal to float. Therefore neither is better than the other.

    Therefore no best operator can be determined. Overload resolution fails.

    We have decided to report a generic error message that simply says that there is no such operator that does what you want, rather than giving the seemingly bizarre and confusing error message “operator overload resolution failed because float is neither better nor worse than decimal”. I think that is a reasonable design choice.

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

Sidebar

Related Questions

I can find tutorials about mapping textures to polygons specifying vertices etc. but nothing
Can anyone recommend a library for chart generation (bar charts, pie charts etc.) which
Can anyone point me to a library for 2D game physics, etc for programming
In SQL you can use SELECT * FROM INFORMATION_SCHEMA.TABLES etc to get information about
Can anyone recommend a good resource -- book, website, article, etc -- to help
Can Eclipse make parameters for generated methods (overwriting, implementing interface, etc.) final, and if
How can I host a ( .Net, Java, VB6, MFC, etc ) application in
How can I visually customize autocomplete fields in Wicket (change colors, fonts, etc.)?
Why I can use Object Initializers in Visual Studio 2008 Windows projects, etc targeted
I want to highlight C/C++/Java/C# etc source codes in my website. How can I

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.