【发布时间】:2016-02-02 02:35:43
【问题描述】:
我尝试在插值字符串中使用条件运算符,但因为它有一个冒号,编译器认为冒号后面是一个格式字符串。
$"test {foo ? "foo is true" : "foo is false"}";
如何使用这种类型的语句? 我唯一想到的是这样的:
var fooString = foo ? "foo is true" : "foo is false";
$"test {fooString}";
【问题讨论】:
-
那是Interpolated string。 Verbatim strings 是那些以
@"开头的,可能包含通常需要转义的字符。
标签: c# conditional-operator string-interpolation