Vote count:
0
in .NET what is the value of "o" and why?
object o = 3/2;
my thinking is that the default type of object is the lowest type that the value will fit... so the least / lowest / smallest object that the answer will fit into is a int32, then that is what is setup as the base class.
Does that seem right?
1 Answer
Vote count:
6
See / Operator (C# Reference):
When you divide two integers, the result is always an integer. For example, the result of 7 / 3 is 2.
Also C# Specification 7.7.2 Division operator:
Integer division:
The division rounds the result towards zero, and the absolute value of the result is the largest possible integer that is less than the absolute value of the quotient of the two operands. The result is zero or positive when the two operands have the same sign and zero or negative when the two operands have opposite signs.
Aucun commentaire:
Enregistrer un commentaire