C#-----字符串反斜杠


C#中转义序列以斜杠(\)开头,当需要输出斜杠\时需要用双斜杠来表示它:

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace ConsoleApplication1
 8 {
 9     class Program
10     {
11         static void Main(string[] args)
12         {
13             string path = "F:\\MiloLu\\2015\\vs\\C#";
14             Console.WriteLine(path);
15             Console.ReadKey();
16         }
17     }
18 }

运行:

F:\MiloLu\2015\vs\C#

从上我们可以看出用双斜杠表示一个单斜杠,容易让人混淆,所以C#提供了另一种替代方式,在字符串前添加@

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace ConsoleApplication1
 8 {
 9     class Program
10     {
11         static void Main(string[] args)
12         {
13             string path = @"F:\MiloLu\2015\vs\C#";
14             Console.WriteLine(path);
15             Console.ReadKey();
16         }
17     }
18 }

运行:

F:\MiloLu\2015\vs\C#

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM