Search code examples
c#stringstring-interpolation

Variable inside inner interpolation


This one perfectly works:

($"SELECT * FROM {Table} WHERE Hex = 11 {(isConfirmed ? " AND UserId<>5" : string.empty)}";

Nevertheless besides static 5 value i want to put variable there. I tried to change as follows nevertheless something is wrong:

($"SELECT * FROM {Table} WHERE Hex = 11 {(isConfirmed ? " AND UserId<>"{myVariable} : string.empty)}";

What i am doing wrong?


Solution

  • This should work:

    string query = $"SELECT * FROM {Table} WHERE Hex = 11 {(isConfirmed ? $" AND UserId<>{myVariable}" : string.Empty)}";