c# 反斜杠 双斜杠
C#打印反斜杠(\) (C# printing a backslash (\))
In C#, \ is a special character (sign) – that is used for escape sequences like to print a new line – we use \n, to print a tab – we use \t etc.
在C#中, \是一个特殊字符(符号)–用于转义序列,例如打印新行–我们使用\ n ,打印制表符–我们使用\ t等。
In this case, if we write \ within the message – it will throw an error "Unrecognized escape sequence".
在这种情况下,如果我们在消息中写\ ,则会抛出错误“无法识别的转义序列” 。
To print a backslash (\), we have to use a double backslash (\\).
要打印反斜杠( \ ),我们必须使用双反斜杠( \\ )。
C#代码打印反斜杠 (C# code to print a backslash)
In the below example – we are printing backslash, \n, \t etc
在下面的示例中–我们正在打印反斜杠, \ n , \ t等
// C# program to print backslash (\)
using System;
using System.IO;
using System.Text;
namespace IncludeHelp
{
class Test
{
// Main Method
static void Main(string[] args)
{
// printing "\"
Console.WriteLine("\\");
// printing between string "\"
Console.WriteLine("Hello\\World");
// printing "\"n and "\"t
Console.WriteLine("\\n\\t");
//hit ENTER to exit the program
Console.ReadLine();
}
}
}
Output
输出量
\
Hello\World
\n\t
翻译自: https://www.includehelp.com/dot-net/print-backslash-example-in-c-sharp.aspx
c# 反斜杠 双斜杠