SoFunction
Updated on 2025-03-07

C# Numerical Conversion-Implicit Numerical Conversion Table Reference

What is an implicit conversion

Implicit Conversion

Implicit conversion is to use it directly, for example, you can use a byte type directly on int.

For example, the following directly assigns b of byte to n of int, and uses it directly. There are no additional keywords, and the system automatically completes the type conversion.

Copy the codeThe code is as follows:

byte b = 1;
int n = b;


Implicit numerical conversion table (excerpted from MSDN)

from

arrive

sbyte

shortintlongfloatdouble or decimal

byte

shortushortintuintlongulongfloatdouble or decimal

short

intlongfloatdouble or decimal

ushort

intuintlongulongfloatdouble or decimal

int

longfloatdouble or decimal

uint

longulongfloatdouble or decimal

long

floatdouble or decimal

char

ushortintuintlongulongfloatdouble or decimal

float

double

ulong

floatdouble or decimal


Notes (excerpted from MSDN)

The accuracy of the conversion from int, uint, or long to float and from long to double may be reduced, but the numerical size is not affected.

There is no implicit conversion to char type.
There is no implicit conversion between floating point type and decimal type.
A constant expression of type int 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.