如何将双引号字符附加到字符串?

时间:2015-01-09 12:33:11

标签: c#

我正在尝试将C#属性创建为字符串作为实验的一部分,但我收到错误“输入字符串的格式不正确”。

这是因为quote

如何正确地将双引号字符附加到字符串?

这是代码:

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

1 个答案:

答案 0 :(得分:4)

逃避不属于格式掩码的大括号(通过加倍):

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