📜  程序在C#中打印反斜杠()

📅  最后修改于: 2021-05-29 23:38:23             🧑  作者: Mango

\是C#中的特殊字符(符号)。它用于转义序列(中断),例如打印新行–我们使用\ n,打印制表符–我们使用\ t 。我们必须使用双反斜杠(\\)来打印反斜杠(\)

如果我们在消息中写\,则会抛出错误“无法识别的转义序列”

例子:

Input  : \\
         Geeksfor\\Geeks
Output : \
         Geeksfor\Geeks
        
Input : Clean\\Evironment
Output: Clean\Evironment

下面是上述方法的实现:

范例1:

// C# program to print backslash (\)
using System;
using System.IO;
using System.Text;
  
namespace geeks {
  
class GFG {
  
    // Main Method
    static void Main(string[] args)
    {
        // to print "\"
        Console.WriteLine("\\");
  
        // to print "\" between string
        Console.WriteLine("Geeksfor\\Geeks");
    }
}
}

输出:

\
Geeksfor\Geeks

范例2:

// C# program to print backslash (\)
using System;
using System.Text;
  
namespace geeks {
  
class GFG {
  
    // Main Method
    static void Main(string[] args)
    {
  
        // to print "\" between string
        Console.WriteLine("Green\Clean");
    }
}
}

错误:

Unrecognized escape sequence `\C'

范例3:

// C# program to print backslash (\)
using System;
using System.Text;
  
namespace geeks {
  
class GFG {
  
    // Main Method
    static void Main(string[] args)
    {
  
        // to print "\" between string
        Console.WriteLine("Clean\\Evironment");
  
        // to print "\"n and "\"t
        Console.WriteLine("\\n\\t");
    }
}
}

输出:

Clean\Evironment
\n\t