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

  • SEARCH
  • Home
  • 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 8300063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:24:46+00:00 2026-06-08T16:24:46+00:00

I know why this is not allowed: ulong x = 0xFEDCBA9876543210; long y =

  • 0

I know why this is not allowed:

ulong x = 0xFEDCBA9876543210;
long y = Int64.MaxValue;
Console.WriteLine(x < y);

Obviously, there is no way for the runtime to implicitly cast either operand to the other type or a larger type to make the comparison work.

Operator ‘<‘ cannot be applied to operands of type ‘ulong’ and ‘long’.

So, this is also not allowed (with MinValue and const):

ulong x = 0xFEDCBA9876543210;
const long y = Int64.MinValue;
Console.WriteLine(x < y);

Yet, this is allowed (with MaxValue instead):

ulong x = 0xFEDCBA9876543210;
const long y = Int64.MaxValue;
Console.WriteLine(x < y);

There is no overload of < accepting a ulong and long, but I saw with Reflector that this will silently convert Int64.MaxValue to a ulong. But this does not always happen. How does it work, and what considerations are the reason for this inconsistency?

  • 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-08T16:24:50+00:00Added an answer on June 8, 2026 at 4:24 pm

    One big difference between long y = Int64.MaxValue; if (x < y)... and if (x < Int64.MaxValue) is that in the latter case the compiler can actually see the constant value if it desired to. It can see that the actual constant value fits in the ulong range and therefore an implicit cast is ok.

    For a plain variable long y, the compiler can’t make any assumptions about what the runtime value of y is. Nevermind that the assignment statement is just one statement up; the compiler doesn’t keep track of values assigned to variables.

    As noted by DarkGray, a const var behaves as a constant since you have told the compiler that its value will never change.

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

Sidebar

Related Questions

I know this is not the proper way to do this, however I am
I know this is not the only question out there, but I still couldn't
So I'll say right up front, obviously I know this is not actually secure
I know this is not programming related, but I have a scenario. Each video
Hey. I know this is not a 'refactor my code' site but I made
I know this question is not really important.. however I've been wondering: Which of
I know this might sounds not reasonable, and might be a bad design. But
Anyone know why this is not returning a value? Example $item2['data'] where it =
Does someone know why this is not a strict quine ? _0='_0=%r;print _0%%_0';print _0%_0
Go ahead and let me know if this is not possible: I need to

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.