Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. What exactly does the '@' symbol do in front of a string?

What exactly does the '@' symbol do in front of a string?

Scheduled Pinned Locked Moved C#
question
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jacobjordan
    wrote on last edited by
    #1

    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."

    S E J T 4 Replies Last reply
    0
    • J jacobjordan

      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."

      S Offline
      S Offline
      Sunset Towers
      wrote on last edited by
      #2

      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"

      1 Reply Last reply
      0
      • J jacobjordan

        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."

        E Offline
        E Offline
        Eslam Afifi
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • J jacobjordan

          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."

          J Offline
          J Offline
          jacobjordan
          wrote on last edited by
          #4

          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."

          1 Reply Last reply
          0
          • J jacobjordan

            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."

            T Offline
            T Offline
            Timmy Kokke
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups