What are all the uses of "@" in C #?

I noticed this piece of code:

 FileInfo[] files =new DirectoryInfo(@"C:\").GetFiles();

What is the purpose @? Are there other uses?

+5
source share
7 answers

String literals

C # supports two forms of string literals: regular string literals and literal string literals .

A regular string literal consists of zero or more characters enclosed in double quotes, as in "hello", and can include both simple escape sequences (such as \ t for a tab character) and hexadecimal and Unicode escape sequences.

A verbatim string literal @, , . @ "". , escape-. , escape- Unicode escape- . .

1:

@"C:\Path\File.zip" == "C:\\Path\\File.zip"

// where

"C:\\Path\\File.zip" // regular string literal
@"C:\Path\File.zip"  // verbatim string literal

. .

2:

@"He said: ""Hello""" == "He said: \"Hello\""

:

"@" , . @ , . @ . @ , , , .

:

class @class
{
   public static void @static(bool @bool) {
      if (@bool)
         System.Console.WriteLine("true");
      else
         System.Console.WriteLine("false");
   }
}
class Class1
{
    static void M() {
        cl\u0061ss.st\u0061tic(true);
    }
}
+21

@ #:

  • ,, " , , escape-". . , @"\n\t" "\\n\\t".

  • " , ". , int @this "this", , this .

+7

@ : " , ". .

, @ "C: \" == "C: \\" (\).

RegEx... RegEx , .., .

+2

verbatim string literal, , escape-.

a @, , . @"hello". , , - . , escape- Unicode-escape . .

quote-escape-sequence: ""

, - "" " .

+2

@ , ( "C: \" ).

+1

@, , . :

verbatim , escape- , , , : @ "c:\Docs\Source\a.txt", "c:\\Docs\\Source\\a.txt"

+1

All Articles