评价条件(三元)在C#插值字符串表达式$
问题描述:
我想在下面的代码行摆脱+符号的操作
Console.Write($"[{(this.Next == null ? this.Val.ToString() : this.Val.ToString()+ "->")}]");
这个例子中的简单的参考可以在这里找到C# interpolated string with conditional-operator和这里How to use the ternary operator inside an interpolated string?倒是这些例子我想追加额外的字符串中的条件之一
答
移动静态部分以外的计算
Console.Write($"[{this.Val.ToString()}{(this.Next == null ? string.Empty : "->")}]");
问题不清楚 –