Shortest way to check for null and assign another value if not

前端 未结 11 2300
伪装坚强ぢ
伪装坚强ぢ 2020-12-13 01:32

I am pulling varchar values out of a DB and want to set the string I am assigning them to as \"\" if they are null. I\'m currently doi

11条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-13 02:16

    With C#6 there is a slightly shorter way for the case where planRec.approved_by is not a string:

    this.approved_by = planRec.approved_by?.ToString() ?? "";
    

提交回复
热议问题