@前缀对C#中的字符串文字有何作用 [英] What does the @ prefix do on string literals in C#
本文介绍了@前缀对C#中的字符串文字有何作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我阅读了一些C#文章,以使用Path.Combine
(part1,part2)组合路径.
I read some C# article to combine a path using Path.Combine
(part1,part2).
它使用以下内容:
string part1 = @"c:\temp";
string part2 = @"assembly.txt";
我可以知道第1部分和第2部分中@
的用途是什么吗?
May I know what is the use of @
in part1 and part2?
推荐答案
@
与任何方法都不相关.
@
is not related to any method.
这意味着您无需在符号后的字符串中转义特殊字符:
It means that you don't need to escape special characters in the string following to the symbol:
@"c:\temp"
等于
"c:\\temp"
这种字符串称为'verbatim'或@引号.请参见 MSDN .
Such string is called 'verbatim' or @-quoted. See MSDN.
这篇关于@前缀对C#中的字符串文字有何作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文