C# C# Basics (Retired) Perfect Integers and Doubles

C# Question

My question is this; b is an integer, c is a double. the video states that any arithmetic operation involving an int and double ends in a double. so int 2 * double 3.5 = double 7.0 but this can not be done without a cast? and now I have another int, int 3 being divided by double 7 with no cast. shouldn't this throw an explicit conversion error and not compile? i entered different answers for the problem but got it wrong each time. does anyone know the solution. Thank you.

1 Answer

Christian Mangeng
Christian Mangeng
15,962 Points

Hi terence,

if at least one of the two numbers is a double, the result will automatically be of type double. This does not require to convert the integer to a double. Therefore, no conversion error will result when dividing an int by a double.