C#'@'字符串前 [英] C# '@' before a String
问题描述
可能重复:
什么是@的字符串.NET面前?一>
我在C#研究书发现了这个
I found this in a C# study book
DirectoryInfo dir = new DirectoryInfo(key.Key.ToString() + @":\");
这本书却没有解释'@'符号是什么。我想但它没有被列入其中搜索 MSDN C#运算符。我可以猜到,它允许开发人员没有逃脱\或是否允许没有任何转义序列?
The book however did not explain what the '@' symbol was for. I tried searching MSDN C# Operators but its not listed there. I can guess that it allows the developer to not have to escape a '\' or does it allow to not have any escape sequences?
这是什么的,我为什么会使用 @:\
而不是:\\
?
What is this for and why would I use @":\"
instead of ":\\"
?
感谢您的帮助
编辑:见注释下一个类似的问题
See the comment below for a similar question
推荐答案
这意味着国米preT字符串字面(即字符串中,如果您使用@ preFIX你无法逃避任何字符) 。它增强可读性在它可用于例
It means to interpret the string literally (that is, you cannot escape any characters within the string if you use the @ prefix). It enhances readability in cases where it can be used.
例如,如果你有一个UNC路径工作,这样的:
For example, if you were working with a UNC path, this:
@"\\servername\share\folder"
是更好的比这个:
is nicer than this:
"\\\\servername\\share\\folder"
这篇关于C#'@'字符串前的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!