Cannot implicitly convert type 'decimal?' to 'decimal'.

前端 未结 4 933
南笙
南笙 2021-01-04 10:08

sdr is my sqldatareader and I want to check that the curPrice value which is of type decimal is null.

inrec.curPrice = sdr.IsDBNull(7) ? (decimal?)null : sdr.

4条回答
  •  [愿得一人]
    2021-01-04 11:02

    decimal? indicates that it's a nullable decimal; you have to use the Value property to get the actual value (if it exists, determined via HasValue).

    I'm assuming curPrice is a non-nullable decimal, in which case you need to also figure out a better value to return than null from the true side of your ternary operator.

提交回复
热议问题