Skip to content

Latest commit

 

History

History
53 lines (45 loc) · 3.01 KB

File metadata and controls

53 lines (45 loc) · 3.01 KB
title Implicit Numeric Conversions Table (C# Reference)
ms.date 07/20/2015
ms.prod .net
ms.technology
devlang-csharp
ms.topic article
helpviewer_keywords
conversions [C#], implicit numeric
implicit numeric conversions [C#]
numeric conversions [C#], implicit
types [C#], implicit numeric conversions
ms.assetid 72eb5a94-0491-48bf-8032-d7ebfdfeb8d8
caps.latest.revision 12
author BillWagner
ms.author wiwagn

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

Remarks

  • Precision but not magnitude might be lost in the conversions from int, uint, long, or ulong to float and from long or ulong to double.

  • 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.

C# Language Specification

[!INCLUDECSharplangspec]

See Also

C# Reference
C# Programming Guide
Integral Types Table
Built-In Types Table
Explicit Numeric Conversions Table
Casting and Type Conversions