码迷,mamicode.com
首页 > Windows程序 > 详细

c#中的转义字符'@' '\' '\\'

时间:2017-05-24 00:49:16      阅读:246      评论:0      收藏:0      [点我收藏+]

标签:pre   color   写法   style   作用   log   rgs   ring   报错   

技术分享

转义字符‘\‘  指的是‘\‘加字符有特殊作用如‘\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";

 

c#中的转义字符'@' '\' '\\'

标签:pre   color   写法   style   作用   log   rgs   ring   报错   

原文地址:http://www.cnblogs.com/lt123/p/6896738.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!