Compiler Value Type Resolution and Hardcoded “0” Integer Values

后端 未结 5 903
野的像风
野的像风 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:32

    When resolving the type for an overloaded method, C# selects the most specific option. The SqlParameter class has two constructors that take exactly two arguments, SqlParameter(String, SqlDbType) and SqlParameter(String, Object). When you provide the literal 0, it can be interpreted as an Object or as a SqlDbType. Since SqlDbType is more specific than Object, it is assumed to be the intent.

    You can read more about overload resolution in this answer.

提交回复
热议问题