Это зависит от того, в каком контексте вы находитесь. Если вы будете использовать , проверенный
контекст, вы получите исключение. Соответствующий раздел спекуляции - раздел 6.2.1:
For a conversion from float or double to an integral type, the processing depends on the overflow checking context (§7.6.12) in which the conversion takes place:
- In a checked context, the conversion proceeds as follows:
- If the value of the operand is NaN or infinite, a System.OverflowException is thrown.
- Otherwise, the source operand is rounded towards zero to the nearest integral value. If this integral value is within the range of the destination type then this value is the result of the conversion.
- Otherwise, a System.OverflowException is thrown.
- In an unchecked context, the conversion always succeeds, and proceeds as follows.
- If the value of the operand is NaN or infinite, the result of the conversion is an unspecified value of the destination type.
- Otherwise, the source operand is rounded towards zero to the nearest integral value. If this integral value is within the range of the destination type then this value is the result of the conversion.
- Otherwise, the result of the conversion is an unspecified value of the destination type.
Таким образом в незарегистрированном контексте, ответить не обязательно 0 - это - неуказанное интервал
стоимость. На самом деле, в моем тестировании, это подходит как интервал. MinValue
, а не 0 в незарегистрированном контексте.
Но существенно, если вы хотите сделать проверку, используют проверенный контекст (по крайней мере, для того выражения).