Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Expand Minimize

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";
   }
}
Show:
© 2015 Microsoft