() operator (C# Reference)
(), are typically used for method or delegate invocation or in cast expressions.
You also use parentheses to specify the order in which to evaluate operations in an expression. For more information, see the Adding parentheses section of the Operators article. For the list of operators ordered by precedence level, see C# operators.
The following example demonstrates how to invoke a method, with or without arguments, and a delegate:
Action<int> display = s => Console.WriteLine(s); var numbers = new List<int>(); numbers.Add(10); numbers.Add(17); display(numbers.Count); // output: 2 numbers.Clear(); display(numbers.Count); // output: 0
A cast expression of the form
(T)E invokes a conversion operator to convert the value of expression
E to type
T. If no explicit conversion exists from the type of
E to type
T, a compile-time error occurs. For information about how to define a conversion operator, see the explicit and implicit keyword articles.
The following example demonstrates type conversion between numeric types:
double x = 1234.7; int a = (int)x; Console.WriteLine(a); // output: 1234
For more information about predefined explicit conversions between numeric types, see Explicit numeric conversions table.
() cannot be overloaded.
C# language specification
We'd love to hear your thoughts. Choose the type you'd like to provide:
Our feedback system is built on GitHub Issues. Read more on our blog.