# Tuesday, 18 May 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
Line2

Line4";

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

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

aqeelasghar2000@gmail.com
Aqeel
Monday, 15 October 2007 01:15:05 (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.
Jeremiah
Monday, 22 October 2007 07:42:06 (Romance Daylight Time, UTC+02:00)
Why does the code below return "\\simonj"

string s1 = @"\simonj";
Simon
Monday, 22 October 2007 07:50:43 (Romance Daylight Time, UTC+02:00)
The @ sign automagically terminates special chars in your string. A terminated \ will be \\ that's the reason.
Monday, 22 October 2007 08:59:55 (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"
Simon
Saturday, 05 January 2008 08:10:37 (Romance Standard Time, UTC+01:00)
You smart :P
Paul
Monday, 14 April 2008 16:26:26 (Romance Daylight Time, UTC+02:00)
Instead of using \\ wouldn't you use Path.DirectorySeparatorChar ??
Rick
Monday, 14 April 2008 16:32:06 (Romance Daylight Time, UTC+02:00)
You would, yes, but the content of the string wasn't really the point.
Wednesday, 07 May 2008 08:24:43 (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. ;)
Andrew
Friday, 09 May 2008 11:24:09 (Romance Daylight Time, UTC+02:00)
I'm glad I could help you out.
Comments are closed.