添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
可爱的酱肘子  ·  Spring ...·  2 年前    · 
不羁的手术刀  ·  font awsome not ...·  2 年前    · 
玩足球的风衣  ·  snprintf (File ...·  2 年前    · 

转义序列无法识别

意外字符遵循 转义序列 或字符文本的 字符串 中的反斜杠 (\)。 编译器需要一个有效的转义字符。 有关详细信息,请参阅 字符转义

下面的示例生成 CS1009。

// CS1009-a.cs  
class MyClass  
   static void Main()  
      // The following escape sequence causes CS1009:  
      string a = "\m";
      // Try the following line instead.  
      // string a = "\t";  
      // The following character literals causes CS1009:
      // CS1009; a lowercase \u-style Unicode escape sequence must have exactly 4 hex digits
      string unicodeEscapeSequence = '\u061';
      // CS1009; a hex escape sequence must start with lowercase \x
      string hexEscapeSequence = '\X061';
      // CS1009; an uppercase \U-style Unicode escape sequence must have exactly 8 hex digits
      string uppercaseUnicodeEscape = '\U0061';

发生该错误的原因通常是在文件名中使用了反斜杠字符,如下面的示例所示。

string filename = "c:\myFolder\myFile.txt";  

若要纠正该错误,请使用“\\”或前面带有 @ 且用引号括起的字符串,如下面的示例所示。

// CS1009-b.cs  
class MyClass  
   static void Main()  
      // The following line causes CS1009.  
      string filename = "c:\myFolder\myFile.txt";
      // Try one of the following lines instead.  
      // string filename = "c:\\myFolder\\myFile.txt";  
      // string filename = @"c:\myFolder\myFile.txt";  
  • string
  •