Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "@" mean in C# [duplicate]

Tags:

c#

Possible Duplicate:
when to use @ in c# ?

F.e. string sqlSelect = @"SELECT * FROM Sales".

like image 794
Mike Avatar asked Mar 02 '10 08:03

Mike


People also ask

What does %= mean in C?

%= Modulus AND assignment operator. It takes modulus using two operands and assigns the result to the left operand. C %= A is equivalent to C = C % A.

What does '#' mean in C?

The only use of '#' in C is to introduce a “pre-processor directive”. C assumes that there is a step that happens before the normal compilation step that processes any lines that start with a '#' symbol. Hence, we have things like: #include “somefile.h”

What does %d do in C?

%d is a format specifier, used in C Language. Now a format specifier is indicated by a % (percentage symbol) before the letter describing it. In simple words, a format specifier tells us the type of data to store and print. Now, %d represents the signed decimal integer.


2 Answers

It means interpret the following string as literal. Meaning, the \ in the string will actually be a "\" in the output, rather than having to put "\\" to mean the literal character

like image 149
Sarfraz Avatar answered Sep 28 '22 04:09

Sarfraz


Before string it allows different string formating rules. You can't use backslash to specify special symbols and "" (double quotes become quotes). I find this format very useful for regular expressions

Example

Console.WriteLine(@"\n""\/a"); // outputs \n"\/a 
Console.WriteLine("\\n\"\"\\/a"); // outputs \n"\/a

You might also seen @ symbol before variable. In such case it allows using special C# keywords as variables.

Example:

var @switch = 1;
var @if = "test";
like image 20
Sergej Andrejev Avatar answered Sep 28 '22 04:09

Sergej Andrejev