C # value conversion-implicit value conversion table reference

Source: Internet
Author: User

What is implicit conversion?

Implicit Conversion

Implicit conversion is used directly. For example, you can use a byte type directly on the int type.

For example, the following directly assigns the byte B to the int n, which is directly used. No additional keywords exist, and the system automatically converts all types.

Copy codeThe Code is as follows: byte B = 1;
Int n = B;

Implicit numeric conversion table (from MSDN)

Slave

To

Sbyte

Short, int, long, float, double, or decimal

Byte

Short, ushort, int, uint, long, ulong, float, double, or decimal

Short

Int, long, float, double, or decimal

Ushort

Int, uint, long, ulong, float, double, or decimal

Int

Long, float, double, or decimal

Uint

Long, ulong, float, double, or decimal

Long

Float, double, or decimal

Char

Ushort, int, uint, long, ulong, float, double, or decimal

Float

Double

Ulong

Float, double, or decimal

Remarks (from MSDN)

The conversion from int, uint, long to float and the conversion from long to double may be less precise, but the value size is not affected.

There is no implicit conversion to the char type.
There is no implicit conversion between the floating point type and the decimal type.
A constant expression of the int type can be converted to sbyte, byte, short, ushort, uint, or ulong, provided that the value of the constant expression is within the range of the target type.

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.