DaveDev
DaveDev

Reputation: 42225

How to append double quote character to a string?

I'm trying to create a C# property as a string as part of an experiment, but I'm getting the error "Input string was not in the correct format".

Is this because of the quote?

How can I properly append the double quote character to the string?

this is the code:

string quote = "\"";
string propName = "MyPropName";
string propVal = "MyPropVal";
string csProperty = string.Format("public string {0} { get { return {1}; } }", propName, quote + propVal + quote);

Upvotes: 0

Views: 151

Answers (1)

Alex K.
Alex K.

Reputation: 175976

Escape the braces (by doubling) that are not part of the format mask:

string csProperty = string.Format("public string {0} {{ get {{ return {1}; }} }}", propName, quote + propVal + quote);

Upvotes: 4

Related Questions