在C#定界符字符串 [英] Heredoc strings in C#
本文介绍了在C#定界符字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有在C#中的字符串,heredoc标注,最好是在那里我没有逃跑的任何的(包括双引号,这是在逐字字符串的一个怪癖)?
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)?
推荐答案
正如其他人所说,没有。
As others have said, there isn't.
我个人避免制造他们虽然第一名 - 我会用嵌入的资源来代替。他们是很容易的工作,如果你有一个实用的方法来加载从调用程序集名为嵌入的资源作为一个字符串(可能假定UTF-8编码),这意味着:
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:
- 如果您的嵌入文档是像SQL,XSLT,HTML等你会得到语法高亮,因为它确实会的是的一个SQL(等)文件
- 您不需要担心的任何的转义
- 您不必担心任何的缩进文档或使你的C#代码看起来很丑陋
- 您可以使用该文件在一个正常的方式,如果这是相关的(如将其视为一个HTML页面)
- 您的数据从您的代码
- 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
这篇关于在C#定界符字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文