C#'@'字符串前字符串

由网友(一组有文采又有创意的昵称与大家分享啦,这类昵称一直以来都非常)分享简介:可能重复: 什么是@的字符串.NET面前? 我在C#研究书发现了这个I found this in a C# study bookDirectoryInfo dir = new DirectoryInfo(key.Key.ToString() + @":\");这本书却没有解释'@'符号是什么。我想但它没有被列...

可能重复:   什么是@的字符串.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:

@"servernamesharefolder"

是更好的比这个:

is nicer than this:

"servernamesharefolder"
阅读全文

相关推荐

最新文章