How do I check for null or empty string for many arguments? - C#

后端 未结 4 649
-上瘾入骨i
-上瘾入骨i 2021-01-20 05:51

I have the below method, which I need to check for whether the arguments are empty or null.

    public DB Where(string field, string operat, string value, s         


        
4条回答
  •  滥情空心
    2021-01-20 06:13

    You could do this:

    int? GetLength(string s) {
        return s == "" ? -1 : s?.Length;
    }
    
    // s1, s2 and so on are your parameters
    int? lengthSum = GetLength(s1) + GetLength(s2); // and so on
    int wholeLength = (s1 + s2).Length; // and so on
    if(lengthSum == wholeLength) {
        // No parameter is null or empty
    }
    

提交回复
热议问题