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