NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

() Operator

In addition to being used to specify the order of operations in an expression, parentheses are used to specify casts (type conversions):

( type ) expr
where:
type
The name of the type to which expr is to be converted.
expr
An expression.

Remarks

A cast explicitly invokes the conversion operator from expr's type to type; the cast will fail if no such conversion operator is defined. To define a conversion operator, see explicit and implicit.

Example

The following program casts a double to an int. The program won't compile without the cast.

using System;
class Test {
   public static void Main() {
      double x = 1234.7;
      int a;
      a = (int)x; // cast double to int
      Console.WriteLine(a);
   }
}

Output

1234

See Also

C# Operators | CLR 7.6.10 Cast expressions | explicit