首页 > 编程 > C# > 正文

C#中转义字符的作用及使用方法

2023-05-02 19:48:22
字体:
来源:转载
供稿:网友

本案例的目的是使学生掌握C#中转义字符的使用方法及作用。

C#中有些字符需要使用转义字符来实现输出,其使用“/"引领。

本案例源代码如下:

using System;

namespace EscapeCharacter
{
  class Program
  {
    static void Main(string[] args)
    {
      char ch1 = '/'';
      char ch2 = '/"';
      char ch3 = '/xff';

      string s1 = "/aI Love /nBeiJing,/tYou Love /nShangHai.";
      string s2 = "Say /"Hello/" to me.";
      string s3 = "abcdef/bghi/rjklmn";
      Console.WriteLine(ch1);
      Console.WriteLine(ch2);
      Console.WriteLine(ch3);
      Console.WriteLine("s1:/n" + s1);
      Console.WriteLine("s2:/n" + s2);
      Console.WriteLine("s3:/n" + s3);
    }
  }
}

输出结果如下
'
"
?
s1:
I Love
BeiJing, You Love
ShangHai.
s2:
Say "Hello" to me.
s3:
jklmnghi

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表