1

How can I stores something like the following string in C#:

string mystring = @"CMD.AddParameters("@Pkey", SqlDbType.Int, Pkey.ToString());";
rtuner
  • 2,362
  • 3
  • 25
  • 37
  • possible duplicate of [In C#, can I escape a double quote in a verbatim string literal?](http://stackoverflow.com/questions/1928909/in-c-can-i-escape-a-double-quote-in-a-verbatim-string-literal) – Sergey Kalinichenko Aug 02 '13 at 17:37
  • @dasblinkenlight Not really a duplicate (of that particular question) since the code in this question is a regular string literal, not a verbatim literal (`@""`). – cdhowie Aug 02 '13 at 17:38
  • 1
    @cdhowie OP wants to put that literal into a verbatim string literal, though. – Sergey Kalinichenko Aug 02 '13 at 17:39

2 Answers2

6
string mystring = "CMD.AddParameters(\"@Pkey\", SqlDbType.Int, Pkey.ToString());";

or

string mystring = @"CMD.AddParameters(""@Pkey"", SqlDbType.Int, Pkey.ToString());";
2
  • escape using the backslash:
    "CMD.AddParameters(\"@Pkey\", SqlDbType.Int, Pkey.ToString());"
  • use unicode literals:
    "CMD.AddParameters(\u0022@Pkey\u0022, SqlDbType.Int, Pkey.ToString());"

fwiw, here is a link to msdn on C# verbatim strings.

collapsar
  • 17,010
  • 4
  • 35
  • 61