dotnet Core in value overflow

Source: Internet
Author: User
Tags dotnet

In. NET core, the int type with C # has a range of upper and lower values, as follows:

int int . MaxValue; int int . MinValue; Console.WriteLine ($"Therange of integers is {min} to {max}");

Run to get results

The range of integers is-2147483648 to 2147483647


At this point, if you execute the following code

int 3 ; Console.WriteLine ($"anexample of overflow: {what}");

Get the range result is

An example of overflow:-2147483646

It's strange that the execution max+3 get the result min+2

Check out the official tutorials

If a calculation produces a value that exceeds those limits, you had an underflow or overflow condition.

If the calculation produces a value that exceeds these limits, a underflow or overflow condition occurs.

Max+3 The overflow occurred, it became min+2.

This is another condition in Python.

Import SYS Print Sys.maxint

Get the maximum value 2147483647

Then perform the following

Print sys.maxint+3

Get 2147483650

See no, no overflow, originally python after int exceeds the maximum value, automatically convert it to a long type, so there is no overflow, as long as the memory is large enough.

dotnet Core in value overflow

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.