16
使用Null合并运算符的独特方法
已关闭。这个问题是基于观点的。它当前不接受答案。 想改善这个问题吗?更新问题,以便通过编辑此帖子以事实和引用的形式回答。 2个月前关闭。 改善这个问题 我知道在C#中使用Null合并运算符的标准方法是设置默认值。 string nobody = null; string somebody = "Bob Saget"; string anybody = ""; anybody = nobody ?? "Mr. T"; // returns Mr. T anybody = somebody ?? "Mr. T"; // returns "Bob Saget" 但是还有什么??用呢?它看起来不像三元运算符有用,除了比以下内容更简洁和易于阅读之外: nobody = null; anybody = nobody == null ? "Bob Saget" …