Can I cast from DBNull to a Nullable Bool in one line?

后端 未结 5 810
南笙
南笙 2021-02-19 04:37

I have a database query which will either return NULL or a boolean (bit) value.

I wish to store this value in a variable of type Nullable<

5条回答
  •  梦如初夏
    2021-02-19 05:00

    You could write value as bool?.
    This will return null if value is not of type bool.

    Note that this is somewhat inefficient.

提交回复
热议问题