Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
In addition to being used to specify the order of operations in an expression, parentheses are used to specify casts, or type conversions:
double x = 1234.7;
int a;
a = (int)x; // cast double to int
Remarks
A cast explicitly invokes the conversion operator from one type to another; the cast will fail if no such conversion operator is defined. To define a conversion operator, see explicit and implicit.
The () operator cannot be overloaded.
For more information, see Casting (C# Programming Guide).
A cast expression can lead to ambiguous syntax. For example, the expression (x)–y could either be interpreted as a cast expression (a cast of –y to type x) or as an additive expression combined with a parenthesized expression, which computes the value x – y.
C# Language Specification
For more information, see the following sections in the C# Language Specification:
1.6.6.5 Operators
7.2 Operators