Basic Conversions
Conversions allow moving the value of one variable into another. There are two types of conversions: explicit and implicit. Implicit conversions happen without intervention. Table 2.7 shows the legal implicit conversions for C# simple types. In addition, the integer literal 0 (zero) can be implicitly converted to an enum. There are no implicit conversions to the char type.
Type | Allowable Conversions |
---|---|
bool | none |
char | ushort, int, uint, long, ulong, float, double, decimal |
sbyte | short, int, long, float, double, decimal |
byte | short, ushort, int, uint, long, ulong, float, double, decimal |
short | int, long, float, double, decimal |
Ushort | int, uint, long, ulong, float, double, decimal |
Int | long, ... |
Get C# Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.