我使用以下代码:
string x = str1 ?? str2 ?? str3 ?? "No string";
Run Code Online (Sandbox Code Playgroud)
但是,如果这些字符串(str1,str2,str3)中的任何一个是String.Empty,那么!= null?
我该如何处理这种情况?
你不能用??.你可以使用Linq做这样的事情:
string x = new[]{ str1, str2, str3, "No string" }.First(x => !string.IsNullOrEmpty(x));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
217 次 |
| 最近记录: |