tags:

views:

105

answers:

2

Is there a heredoc notation for strings in C#, preferably one where I don't have to escape anything (including double quotes, which are a quirk in verbatim strings)?

A: 
polygenelubricants
+4  A: 

As others have said, there isn't.

Personally I would avoid creating them in the first place though - I would use an embedded resource instead. They're pretty easy to work with, and if you have a utility method to load a named embedded resource from the calling assembly as a string (probably assuming UTF-8 encoding) it means that:

  • If your embedded document is something like SQL, XSLT, HTML etc you'll get syntax highlighting because it really will be a SQL (etc) file
  • You don't need to worry about any escaping
  • You don't need to worry about either indenting your document or making your C# code look ugly
  • You can use the file in a "normal" way if that's relevant (e.g. view it as an HTML page)
  • Your data is separated from your code
Jon Skeet
+1 Increasing your reputation by 0.0047%
pessimopoppotamus