Explicit Numeric Conversions

suggest change

Explicit casting operators can be used to perform conversions of numeric types, even though they don’t extend or implement one another.

double value = -1.1;
int number = (int) value;

Note that in cases where the destination type has less precision than the original type, precision will be lost. For example, -1.1 as a double value in the above example becomes -1 as an integer value.

Also, numeric conversions rely on compile-time types, so they won’t work if the numeric types have been “boxed” into objects.

object value = -1.1;
int number = (int) value; // throws InvalidCastException

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Casting:
* Explicit Numeric Conversions

Table Of Contents
17 Regex
19 Arrays
21 Enum
22 Tuples
24 GUID
27 Looping
36 Casting
46 Methods
88 Events
92 Structs
104 Indexer
106 Stream
107 Timers
109 Threading
127 Caching
135 Pointers
147 C# Script