Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do we use @ with "\" while trying to replace it with another string [duplicate]

Possible Duplicate:
What's the @ in front of a string in C#?

why do we use @ to replace \ with another string using string.replace(@"\","$$") i'm using C# windows application

like image 372
iJade Avatar asked Dec 19 '25 10:12

iJade


2 Answers

The @ in front of a string literal makes it a verbatim string literal, so the backslash \ does not need to be doubled. You can use "\\" instead of @"\" for the same effect.

like image 89
Sergey Kalinichenko Avatar answered Dec 20 '25 22:12

Sergey Kalinichenko


Because if you didn't, you'd have to escape \ with \\

@ is used to what's called verbatim strings

like image 38
Icarus Avatar answered Dec 21 '25 00:12

Icarus