Why does integer division in C# return an integer and not a float?

前端 未结 8 885
隐瞒了意图╮
隐瞒了意图╮ 2020-11-21 04:32

Does anyone know why integer division in C# returns an integer and not a float? What is the idea behind it? (Is it only a legacy of C/C++?)

In C#:

fl         


        
8条回答
  •  你的背包
    2020-11-21 05:13

    Its just a basic operation.

    Remember when you learned to divide. In the beginning we solved 9/6 = 1 with remainder 3.

    9 / 6 == 1  //true
    9 % 6 == 3 // true
    

    The /-operator in combination with the %-operator are used to retrieve those values.

提交回复
热议问题