0

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); 
2

1 Answer 1

4

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); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.