What exactly does the '@' symbol do in front of a string?
-
I have seen some strings formatted like @"Hello World!", or something like that in code i have downloaded on the internet, and i was really wondering what that '@' symbol does. What's the difference between "Hello World!" and @"Hello World!"? Just curious.
void Play() { try { throw Ball(); } catch (Glove) { } finally { Play(); } } "Failure is only the opportunity to begin again, this time more wisely." "Don't ask for a light load, but rather ask for a strong back."
-
I have seen some strings formatted like @"Hello World!", or something like that in code i have downloaded on the internet, and i was really wondering what that '@' symbol does. What's the difference between "Hello World!" and @"Hello World!"? Just curious.
void Play() { try { throw Ball(); } catch (Glove) { } finally { Play(); } } "Failure is only the opportunity to begin again, this time more wisely." "Don't ask for a light load, but rather ask for a strong back."
In the case of @"Hello World!" I don't believe it does anything. However in a directory string @"C:\Program Files\Common Files" you don't have to escape the "\" like you would with out it. "C:\\Program Files\\Common Files"
-
I have seen some strings formatted like @"Hello World!", or something like that in code i have downloaded on the internet, and i was really wondering what that '@' symbol does. What's the difference between "Hello World!" and @"Hello World!"? Just curious.
void Play() { try { throw Ball(); } catch (Glove) { } finally { Play(); } } "Failure is only the opportunity to begin again, this time more wisely." "Don't ask for a light load, but rather ask for a strong back."
The @ character is to ignore escape sequences in a string. Escape sequences are conbinations such as \n \t \u0048 If you have 2 string literals "\u0048ello\nworld" and @"\u0048ello\nworld", the output is Hello world and \u0048ello\nworld For more information, http://www.google.com/search?q=escape+character+string+literal+c%23&rls=com.microsoft:*&ie=UTF-8&oe=UTF-8&startIndex=&startPage=1[^]
Eslam Afifi
-
I have seen some strings formatted like @"Hello World!", or something like that in code i have downloaded on the internet, and i was really wondering what that '@' symbol does. What's the difference between "Hello World!" and @"Hello World!"? Just curious.
void Play() { try { throw Ball(); } catch (Glove) { } finally { Play(); } } "Failure is only the opportunity to begin again, this time more wisely." "Don't ask for a light load, but rather ask for a strong back."
Ok, thanks. Live and learn.
void Play() { try { throw Ball(); } catch (Glove) { } finally { Play(); } } "Failure is only the opportunity to begin again, this time more wisely." "Don't ask for a light load, but rather ask for a strong back."
-
I have seen some strings formatted like @"Hello World!", or something like that in code i have downloaded on the internet, and i was really wondering what that '@' symbol does. What's the difference between "Hello World!" and @"Hello World!"? Just curious.
void Play() { try { throw Ball(); } catch (Glove) { } finally { Play(); } } "Failure is only the opportunity to begin again, this time more wisely." "Don't ask for a light load, but rather ask for a strong back."
I use it a lot when I want large strings, like pieces of xml, to be readable in code. with @ you can write something like this:
string xml = @"
<xml>
<test>
<value>1</value>
<value>2</value>
</test>
</xml>"instead of:
string xml = "<xml><test><value>1</value><value>2</value></test></xml>"
Dawn is nature's way of telling you to go to bed.