Search code examples
c#string-interpolation

How do I use string interpolation with string literals?


I'm trying to do something like

string heading = $"Weight in {imperial?"lbs":"kg"}"

Is this doable somehow?


Solution

  • You should add () because : is used also for string formatting:

    string heading = $"Weight in {(imperial ? "lbs" : "kg")}";