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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:24:00+00:00 2026-06-12T02:24:00+00:00

I was testing something out using LinqPad and was surprised that the following code

  • 0

I was testing something out using LinqPad and was surprised that the following code did not produce an exception:

ulong lSmallValue = 5;
ulong lBigValue = 10;

ulong lDifference = lSmallValue - lBigValue;

Console.WriteLine(lDifference);
Console.WriteLine((long)lDifference);

This produces the following output:

18446744073709551611
-5

Fortunately, I was hoping for this behavior, but I was under the assumption that this would cause an OverflowException to be thrown.

From System.OverflowException:

An OverflowException is thrown at run time under the following conditions:

  • An arithmetic operation produces a result that is outside the range of the data type returned by the operation.
  • A casting or conversion operation attempts to perform a narrowing conversion, and the value of the source data type is outside the range of the target data type.

Why doesn’t the operation lSmallValue - lBigValue fall into the first category?

  • 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-12T02:24:01+00:00Added an answer on June 12, 2026 at 2:24 am

    CLR will not throw the Overflow exception by default. Unless you’re using the “checked” keyword.

    http://msdn.microsoft.com/en-us/library/74b4xzyw%28v=vs.71%29.aspx

    UPD: Actually, I do recommend the “CLR via C#” by Jeffrey Richter – he makes these things so much more transparent. My favorite book about the CLR and C# fundamentals.

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

Sidebar

Related Questions

I recently did some performance testing and analysis of an ASP.NET application using out-of-process
While testing out a UDP multicast server that I've written on Windows 7 Ultimate
I am just starting out with unit testing and have a scenario I'm not
I am refactoring a class so that the code is testable (using NUnit and
I'm testing out the PostgreSQL Text-Search features, using the September data dump from StackOverflow
Using Nodejs Passport, I was testing out what happens when an error condition occurs
I'm finally starting out with unit testing, having known that I should be doing
I'm testing out Eziriz .NET Reactor to protect a software, developed using Visual Studio
I am testing out a property system and I want to make sure that
I was testing something I read earlier about how random Math.random() really is, and

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.