@对字符串和路径做了什么 [英] what does the @ do to strings and paths
问题描述
我看到许多c#代码示例与字符串相关或在
文件路径中使用字符串,其中包含@符号。
例如
string path1 = @" mydir" ;;
string path2 = @" \ mydir" ;;
@ do做什么?
Peted
I see many c# code samples that relate to strings or using strings in
file paths, that have an @ sign.
eg
string path1 = @"mydir";
string path2 = @"\mydir";
what does the @ do ?
Peted
推荐答案
>来自MSDN
--- -------------
@ -quoted字符串文字以@开头,并附在双
引号中。
例如:
@早上好 //字符串文字
@ -quoting的优点是不处理转义序列,
这使得它易于编写,例如,一个完全限定的文件
名称:
@" c:\Docs \Source \ a.txt" //而不是c:\\Docs \\Source \\\.txt
要在@ -quoted字符串中包含双引号,请将其加倍:
@""" Ahoy!""船长叫道。 //啊!船长叫道。
>From MSDN
----------------
@-quoted string literals start with @ and are enclosed in double
quotation marks.
For example:
@"good morning" // a string literal
The advantage of @-quoting is that escape sequences are not processed,
which makes it easy to write, for example, a fully qualified file
name:
@"c:\Docs\Source\a.txt" // rather than "c:\\Docs\\Source\\a.txt"
To include a double quotation mark in an @-quoted string, double it:
@"""Ahoy!"" cried the captain." // "Ahoy!" cried the captain.
Peted写道:
Peted wrote:
string path1 = @" mydir" ;
string path2 = @" \ mydir" ;;
@做什么?
string path1 = @"mydir";
string path2 = @"\mydir";
what does the @ do ?
它禁用反斜杠作为转义字符。没有@,第二个
目录名应该是
string path2 = \\mydir;
Ebbe
It disables the backslash as escape character. Without the @, the second
directory name should have been
string path2 = \\mydir;
Ebbe
< Petedwrote:
<Petedwrote:
我看到许多与字符串或使用相关的c#代码示例
文件路径中的字符串,带有@符号。
I see many c# code samples that relate to strings or using strings in
file paths, that have an @ sign.
参见 http://pobox.com/~skeet/csharp/strings.html#literals
-
Jon Skeet - < ; sk *** @ pobox.com>
http://www.pobox .com / ~siget 博客: http://www.msmvps.com /jon.skeet
如果回复小组,请不要给我发邮件
See http://pobox.com/~skeet/csharp/strings.html#literals
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
这篇关于@对字符串和路径做了什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!