C#-----字符串反斜杠
C#中转义序列以斜杠(\)开头,当需要输出斜杠\时需要⽤双斜杠来表⽰它:
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6
7namespace ConsoleApplication1
8 {
writeline用什么替代9class Program
10    {
11static void Main(string[] args)
12        {
13string path = "F:\\MiloLu\\2015\\vs\\C#";
14            Console.WriteLine(path);
15            Console.ReadKey();
16        }
17    }
18 }
运⾏:
F:\MiloLu\2015\vs\C#
从上我们可以看出⽤双斜杠表⽰⼀个单斜杠,容易让⼈混淆,所以C#提供了另⼀种替代⽅式,在字符串前添加@ 1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6
7namespace ConsoleApplication1
8 {
9class Program
10    {
11static void Main(string[] args)
12        {
13string path = @"F:\MiloLu\2015\vs\C#";
14            Console.WriteLine(path);
15            Console.ReadKey();
16        }
17    }
18 }
运⾏:
F:\MiloLu\2015\vs\C#

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。