Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

Implicit Numeric Conversions Table (C# Reference)

The following table shows the predefined implicit numeric conversions. Implicit conversions might occur in many situations, including method invoking and assignment statements.

From 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

  • The conversions from int, uint, or long to float and from long to double may cause a loss of precision, but not a loss of magnitude.

  • There are no implicit conversions to the char type.

  • There are no implicit conversions between floating-point types and the decimal type.

  • A constant expression of type int can be converted to sbyte, byte, short, ushort, uint, or ulong, provided the value of the constant expression is within the range of the destination type.

For more information, see the C# language specification (C# Language Specification):

  • 6.1 Implicit conversions

  • 7.15 Constant expressions

Community Additions

ADD
Show:
© 2015 Microsoft