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# 反斜杠 双斜杠

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐