C#用一个反斜杠写一个路径和用两个反斜杠写一个路径有什么区别 [英] C# what is the difference between writing a path with one backslash and writing a path with two backslash
本文介绍了C#用一个反斜杠写一个路径和用两个反斜杠写一个路径有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
写C:\Program Files和写C:\\Program Files有什么区别?
以及为什么我们有时写@ \.. 。
What is the difference between write "C:\Program Files" and write "C:\\Program Files"?
and why we write sometimes "@\"...
推荐答案
因为反斜杠字符在字符串中有特殊含义:它说将此字符与下一个字符组合 - 并用实际的特殊代码替换它们字符串
所以\ n
是换行符,\
是字符串中的双引号,\\
是字符串中的反斜杠。
啊,但是...前缀带有'@'字符的字符串文字将其关闭,所以反斜杠又是一个普通字符,如果你想在字符串中输入双引号,你可以输入两个:
Because the backslash character has a special meaning in strings: it says "Combine this character with the next one - and replace them with a special code in the actual string"
So\n
is a Newline character,\"
is a double quote in the string, and\\
is a backslash in the string.
Ah, but... prefixing a string literal with an '@' character turns that off, so backslash is a normal character again, and if you want to enter a double quote into the string you enter two together:
Console.WriteLine(@"hello ""Paul""");
将写作
Will write
Hello "Paul"
写的时候
When you write
"C:\Program Files"
你得到一个错误 - 无法识别的转义序列
You get an error - "Unrecognised escape sequence"
"C:\\Program Files"
你得到的字符串
You get the string
C:\Program Files
和
And
@"C:\Program Files"
会给你同样的东西。
我们何时使用\
简单!
Will give you the same thing.
When do we use \"
Simple!
Console.WriteLine("hello \"Paul\"");
这对你有帮助..
http://social.msdn.microsoft.com/Forums/en-US/accf32eb- 9471-4026-a679-96175080a78a / folder-or-file-location-slash-or- [ ^ ]
this will help you..
http://social.msdn.microsoft.com/Forums/en-US/accf32eb-9471-4026-a679-96175080a78a/folder-or-file-location-slash-or-[^]
这篇关于C#用一个反斜杠写一个路径和用两个反斜杠写一个路径有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文