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

前端 未结 11 2298
伪装坚强ぢ
伪装坚强ぢ 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 01:50

    I use extention method SelfChk

    static class MyExt {
    //Self Check 
     public static void SC(this string you,ref string me)
        {
            me = me ?? you;
        }
    }
    

    Then use like

    string a = null;
    "A".SC(ref a);
    

提交回复
热议问题