Compiler Value Type Resolution and Hardcoded “0” Integer Values

后端 未结 5 922
野的像风
野的像风 2020-11-28 11:50

First, a bit of background. Read the question and accepted answer posted here for a specific scenario for my question. I\'m not sure if other, similar cases exist but this

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-28 12:48

    This is caused by the fact that the integer literal 0 has an implicit conversion to any enum type. The C# specification states:

    6.1.3 Implicit enumeration conversions

    An implicit enumeration conversion permits the decimal-integer-literal 0 to be converted to any enum-type and to any nullable-type whose underlying type is an enum-type. In the latter case the conversion is evaluated by converting to the underlying enum-type and wrapping the result.

    As a result, the most specific overload in this case is SqlParameter(string, DbType).

    This does not apply for other int values, so the SqlParameter(string, object) constructor is the most specific.

提交回复
热议问题