提示空传播运算符出错,有替代写法
node?.InnerText; 提示空传播运算符出错,有无替代写法?

csharp
编辑
1string text = node != null ? node.InnerText : null;

csharp
编辑
1string text = null; 2if (node != null) 3{ 4 text = node.InnerText; 5}

csharp
编辑
1// 当 node 为 null 时,text 会被赋值为 string.Empty 2string text = (node != null ? node.InnerText : null) ?? string.Empty; 

渝公网安备 50011902000225号

渝ICP备18008233号-1