# Tuesday, May 18, 2004

My main focus for this blog is .NET which really isn't apparent when you look at the posts so I thought I'd add an entry about a nifty little language trick I picked up reading blogs last week :)

The @ is a really neat symbol which you use for making C# interpret a string literally. You probably written double \ more than once in a file path. Well with the @ symbol you don't have to do this simply write:

string s = @"c:\windows\Microsoft.NET";

Most C# developers know this but did you know that you can also do this:

string s = @"Line 1


The text will appear just as you wrote it. Pretty neat :)

Tuesday, May 18, 2004 2:02:56 PM (Romance Daylight Time, UTC+02:00)
Indeed it is nifty, I use it alot, especially when working with files :)
Friday, August 11, 2006 8:02:14 AM (Romance Daylight Time, UTC+02:00)
Thatz simply great buddy, thanks a lot
Thursday, February 08, 2007 7:11:55 PM (Romance Standard Time, UTC+01:00)
Also great for regular expressions!
Monday, April 30, 2007 4:12:48 AM (Romance Daylight Time, UTC+02:00)
Great! Thanks
Thursday, July 26, 2007 1:34:42 PM (Romance Daylight Time, UTC+02:00)
what if "@" is used within a string. please reply me on my Email.
Thursday, July 26, 2007 1:35:53 PM (Romance Daylight Time, UTC+02:00)
what if "@" is used within a string. please reply me on my Email.

Monday, October 15, 2007 1:15:05 AM (Romance Daylight Time, UTC+02:00)
Thanks for the information! I'm fairly new to C#, and was reading about XML parsing, when I saw the @ symbol used for a file path. Good explanation.
Monday, October 22, 2007 7:42:06 AM (Romance Daylight Time, UTC+02:00)
Why does the code below return "\\simonj"

string s1 = @"\simonj";
Monday, October 22, 2007 7:50:43 AM (Romance Daylight Time, UTC+02:00)
The @ sign automagically terminates special chars in your string. A terminated \ will be \\ that's the reason.
Monday, October 22, 2007 8:59:55 AM (Romance Daylight Time, UTC+02:00)
so if I want my string to have only 1 "\" , what do I need to do? eg

s1 = "\simonj"
Saturday, January 05, 2008 8:10:37 AM (Romance Standard Time, UTC+01:00)
You smart :P
Monday, April 14, 2008 4:26:26 PM (Romance Daylight Time, UTC+02:00)
Instead of using \\ wouldn't you use Path.DirectorySeparatorChar ??
Monday, April 14, 2008 4:32:06 PM (Romance Daylight Time, UTC+02:00)
You would, yes, but the content of the string wasn't really the point.
Wednesday, May 07, 2008 8:24:43 AM (Romance Daylight Time, UTC+02:00)
Thanks man. I'm a pretty experienced c# developer and I never really took the time to bother learning wtf the @ sign was about. Just used a plugin to format the string for me, and whenever I run into the @, I was like damnit, what is that?? Now I know! :)

Oh and nice popup, showoff. ;)
Friday, May 09, 2008 11:24:09 AM (Romance Daylight Time, UTC+02:00)
I'm glad I could help you out.
Comments are closed.