Compiler Error CS1009

Unrecognized escape sequence

An unexpected character followed a backslash (\) in a string. The compiler expects one of the valid escape characters; see Character Escapes for more information.

The following sample generates CS1009:

// CS1009-a.cs
class MyClass
{
   static void Main()
   {
      string a = "\m";   // CS1009
      // try the following line instead
      // string a = "\t";
   }
}

A common case for this error is using the backslash character in a file name, for example:

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

To resolve this error, use "\\" or the @-quoted string literal, as shown in the following example:

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