The C# Programming Language, Third Edition
by Anders Hejlsberg, Mads Torgersen, Scott Wiltamuth, Peter Golde
6. Conversions
A conversion enables an expression to be treated as being of a particular type. A conversion may cause an expression of a given type to be treated as having a different type, or it may cause an expression without a type to get a type. Conversions can be implicit or explicit, a classification that determines whether an explicit cast is required. For instance, the conversion from type int to type long is implicit, so expressions of type int can implicitly be treated as type long. The opposite conversion, from type long to type int, is explicit, so an explicit cast is required.
int a = 123; long b = a; // Implicit conversion from int to long int c = (int) b; // Explicit conversion from long to int
Some conversions ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access