-1

I want to insert a ternary expression into a interpolation, like this:

var a = $"we have {true ? "a":"b"}";

Software used in compilation:

XBuild Engine Version 14.0
Mono, Version 5.2.0.215

And I used xbuild Cmc.sln(Cmc is my solution name). After that I got error (line 44 is the C# code given above):

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

Why do I get this? I think my code is valid.

Cœur
  • 37,241
  • 25
  • 195
  • 267
ice1000
  • 6,406
  • 4
  • 39
  • 85
  • Yeah, It's duplicate... But I searched `C# tenary` and I didn't get answer. So I opened a new question... Sorry. – ice1000 Sep 04 '17 at 18:05

1 Answers1

1

Try:

$"we have {(true ? "a":"b")}";
Titian Cernicova-Dragomir
  • 230,986
  • 31
  • 415
  • 357