共用方式為


編譯器錯誤 CS1009

更新:2007 年 11 月

錯誤訊息

無法辨認的逸出序列

字串中反斜線 (\) 的後方出現未預期的字元。編譯器需要有效的逸出字元 (Escape Character);如需詳細資訊,請參閱逸出字元

下列範例會產生 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";

若要解決這個錯誤,請使用 "\\" 或 @ 加上引號的字串常值 (String Literal),如下列範例所示:

// 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";
   }
}