Why a result of a division is automatically int in C#? -


i have line:

console.writeline((double)(1 / 4))); 

which outputs: 0.

i debugged it, , compiler treating 1 / 4 0:

compiler converts 1 / 4 0

so understand it, compiler treats 1 / 4 int. why?


note: when write line:

console.writeline((double)1 / 4)); 

it outputs: 0.25.

because 1 , 4 both ints. there no reason compiler make type-conversions. run sample , see outputs:

int x = 1, y = 4;  console.writeline(x / y);  double xx = 1; console.writeline(xx / y);  double yy = 4; console.writeline(x / yy); 

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -