你好,我需要将文件夹路径存储为字符串变量在ASP.Net MVC 4中使用,但是当我使用以下方法时会显示错误:
无法识别的转义序列
static string path="C:\Path";
这个错误的原因是什么,我该如何解决?
你好,我需要将文件夹路径存储为字符串变量在ASP.Net MVC 4中使用,但是当我使用以下方法时会显示错误:
无法识别的转义序列
static string path="C:\Path";
您需要使用另一个 '\' 进行转义,如下所示:
static string path="C:\\Path";
static string path = @"C:\Path";
相关阅读:2.4.4.5 字符串文字
\
以防止字符串被提前关闭。var myString = "This is my string with \"quotes\"";
这被称为转义。为了在字符串中显示反斜杠,您需要使用另一个反斜杠进行转义:
static string path = "C:\\Path";
或者在字符串前加上@符号,这样可以抑制反斜杠转义机制:
static string path = @"C:\Path";