Fairly new to C# and I'm trying to build a clean-ish multi line string using a verbatim string literal, but also trying to pass in variables to it.
Says it is not formatted correctly, so seeing what I am doing wrong here, as this format is close to what I've seen in other SO questions.
var bodyJson =string.Format(@"{
""[email protected]"": ""/consultingprojectses({0})"",
""[email protected]"": ""products(f4b6b505-99df-e711-8108-c4346bdc3201)"",
""[email protected]"": ""/contacts({1})"",
""[email protected]"": ""/accounts({2})""
}", projectRecord.consultingprojectsid, contact, projectRecord.account_value);
Or preferably this:
var bodyJson =string.Format(@"{
'[email protected]': '/consultingprojectses({0})',
'[email protected]': 'products(f4b6b505-99df-e711-8108-c4346bdc3201)',
'[email protected]': '/contacts({1})',
'[email protected]': '/accounts({2})'
}", projectRecord.consultingprojectsid, contact, projectRecord.account_value);
{and}. How to escape braces (curly brackets) in a format string in .NETJObjectto create the necessary structure and values rather than trying to escape and all that; for instance, technically you have invalid JSON because strings must use double quotes, not single quotes.bodyJson.Replace("{0}","myvalue")