コンパイラ エラー CS1009

認識できないエスケープ シーケンスです

エスケープ シーケンスまたは文字リテラルの文字列内の円記号 (\) の後に予期しない文字が続いています。 コンパイラは、有効なエスケープ文字のうち 1 つを要求します。 詳細については、「文字のエスケープ」を参照してください。

次の例では 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";  
   }  
}  

こちらもご覧ください