无法识别的转义序列
在 string 中反斜杠 (/) 的后面是一个意外的字符。编译器需要一个有效的转义符;有关更多信息,请参见字符转义。
下面的示例生成 CS1009:
// CS1009-a.cs
class MyClass
{
static void Main()
{
string a = "/m"; // CS1009
// try the following line instead
// string a = "/t";
}
}
发生该错误的原因通常是在文件名中使用了反斜杠字符,例如:
string filename = "c:/myFolder/myFile.txt";
若要纠正该错误,请使用“//”或前面带有 @ 且用引号括起的字符串,如下面的示例所示:
// CS1009-b.cs
class MyClass
{
static void Main()
{
string filename = "c:/myFolder/myFile.txt"; // CS1009
// try the one of the following lines instead
// string filename = "c://myFolder//myFile.txt";
// string filename = @"c:/myFolder/myFile.txt";
}
}
初学VS2010遇到的(/)无法识别的转义序列问题
最新推荐文章于 2022-04-30 13:05:12 发布