Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Escaping Quotes inside new C# 6 String Syntax

Tags:

c#

c#-6.0

People also ask

How do I escape a single quote in CMD?

It's done by finishing already opened one ( ' ), placing escaped one ( \' ), then opening another one ( ' ). This syntax works for all commands.

How do you escape a single quote inside a single quote?

A single quote is not used where there is already a quoted string. So you can overcome this issue by using a backslash following the single quote. Here the backslash and a quote are used in the “don't” word.

How do you escape quotes inside quotes?

It's done by finishing an already-opened one ( ' ), placing the escaped one ( \' ), and then opening another one ( ' ). It's done by finishing already opened one ( ' ), placing a quote in another quote ( "'" ), and then opening another one ( ' ).

Why do we use double quotes in C?

double quotes in C or C++ In C and C++ the single quote is used to identify the single character, and double quotes are used for string literals. A string literal “x” is a string, it is containing character 'x' and a null terminator '\0'. So “x” is two-character array in this case.


wrap your logic inside parentheses, inside the brackets:

var fullName = $"My name is {(includePrefix ? "Mr. " : "")}{FirstName} {LastName}";

Regularly to escape quotes you need to use a slash (i.e. \").

However, this is not the issue here, as you don't need to escape, you're just missing parentheses over the expression.

This works:

bool includePrefix = true;
var fullName = $"My name is {(includePrefix ? "Mr. " : "")}{FirstName} {LastName}";