lt123

转义字符\'\\'  指的是\'\\'加字符有特殊作用如\'\r\' \'\n\' \'\t\' \'\b\'等

但是有时候字符串不需要转义或原样输出

如 strings="C:\System\1.txt"

可以写成  strings=@"C:\System\1.txt"

 

 static void Main(string[] args)
        {
            string s =  "C:\woo\1.txt";  这样写是会报错
            Console.WriteLine(s);
            Console.ReadKey();
        }

 

正确写法  两种写法都行

  static void Main(string[] args)
        {
            string s = @"C:\woo\1.txt";
            string s1 ="C:\\woo\\1.txt";
            Console.WriteLine(s);
            Console.ReadKey();
        }

当然这种写法也行 但是不推荐 容易混

  string s ="C:/woo/1.txt";

 

分类:

技术点:

相关文章:

  • 2021-10-28
  • 2022-12-23
  • 2021-06-18
  • 2022-12-23
  • 2022-12-23
  • 2021-12-30
  • 2021-08-02
猜你喜欢
  • 2022-12-23
  • 2022-02-09
  • 2022-12-23
相关资源
相似解决方案