Everyone's given you the correct answer so far, I'm adding this so other readers don't miss it in the comments.
Use the same rule as regular math. Inner Parenthesis first. So in the first example, the 1 is casted to a double before the division occurs, making the result a double (division of int and double results in double). This rings true if it is (Double)1/2
or 1/(Double)2
. So in the last example, (Double)(1/2)
, the (1/2)
is performed first, int on int, resulting in int. Then the (Double) casts it to a Double. Hope this not only helps you but anyone else curious about this question. I myself have had many times where I had a long equation and literally had to cast each parameter of the equation to a double.