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

前端 未结 11 2297
伪装坚强ぢ
伪装坚强ぢ 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:00

    Use the C# coalesce operator: ??

    // if Value is not null, newValue = Value else if Value is null newValue is YournullValue
    var newValue = Value ?? YourNullReplacement;
    

提交回复
热议问题