C#:内插值tenary表达式是无效
问题描述:
我想插入一个tenary表达成插值,是这样的:在编译使用C#:内插值tenary表达式是无效
var a = $"we have {true ? "a":"b"}";
软件:
XBuild Engine Version 14.0
Mono, Version 5.2.0.215
而且我用xbuild Cmc.sln
(CMC是我的解决方案名称)。从那以后,我得到了错误(第44行是上面给出的C#代码):
Expr/Expression.cs(44,13): error CS8076: Missing close delimiter '}' for interpolated expression started with '{'.
Expr/Expression.cs(44,25): error CS1003: Syntax error, ':' expected
Expr/Expression.cs(44,25): error CS1733: Expected expression
Expr/Expression.cs(44,27): error CS1002: ; expected
Expr/Expression.cs(44,28): error CS1002: ; expected
为什么会这样?我认为我的代码是有效的。
是啊,这是重复的...但我搜索'C#tenary',我没有得到答案。所以我开了一个新的问题...对不起。 – ice1000