@"string"

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mike Gleason jr Couturier

    @"string"

    Why do I see a @ preceding strings in code examples?

    What does the @ do?


    thanks!


  • Miro

    #2
    Re: @"string&q uot;

    Do you mean for 'parameters' in sql statements?

    Can you post an example of what you see?


    "Mike Gleason jr Couturier" <nospam@invalid host.comwrote in message
    news:urljRJQ4IH A.3500@TK2MSFTN GP05.phx.gbl...
    Why do I see a @ preceding strings in code examples?
    >
    What does the @ do?
    >
    >
    thanks!
    >

    Comment

    • Rory Becker

      #3
      Re: @&quot;string&q uot;

      Hello Mike Gleason jr Couturier,
      Why do I see a @ preceding strings in code examples?
      >
      What does the @ do?
      I believe it is a c# sytax that prevents the compiler otherwise interpreting
      certain characters as escape codes.

      for example
      -------------------------------------------------------------
      string SomeString = "\n"; //This produces an enter keystroke
      string OtherString = @"\n"; //This produces a string containing the backslash
      and 'n' characters.
      -------------------------------------------------------------


      --
      Rory


      Comment

      • Anthony Jones

        #4
        Re: @&quot;string&q uot;

        "Rory Becker" <rorybecker@new sgroup.nospamwr ote in message
        news:3af1034718 d0c8caaf282538d b6d@news.micros oft.com...
        Hello Mike Gleason jr Couturier,
        >
        Why do I see a @ preceding strings in code examples?

        What does the @ do?
        >
        I believe it is a c# sytax that prevents the compiler otherwise
        interpreting
        certain characters as escape codes.
        >
        for example
        -------------------------------------------------------------
        string SomeString = "\n"; //This produces an enter keystroke
        string OtherString = @"\n"; //This produces a string containing the
        backslash
        and 'n' characters.
        -------------------------------------------------------------
        >
        Correct and in addition a string preceded with @ can split across lines:-

        string someSQL = @"
        SELECT a.Field1, a.Field2
        FROM ATable a
        INNER JOIN BTable b ON b.ID = a.ID
        WHERE b.Field3 = 15"

        The down side is that " need to be duplicated as "" e.g.:-

        string someXML = @"<root thing=""x"" />"





        --
        Anthony Jones - MVP ASP/ASP.NET


        Comment

        • Jon Skeet [C# MVP]

          #5
          Re: @&quot;string&q uot;

          Mike Gleason jr Couturier <nospam@invalid host.comwrote:
          Why do I see a @ preceding strings in code examples?
          >
          What does the @ do?
          See http://pobox.com/~skeet/csharp/strings.html

          --
          Jon Skeet - <skeet@pobox.co m>
          Web site: http://www.pobox.com/~skeet
          Blog: http://www.msmvps.com/jon_skeet
          C# in Depth: http://csharpindepth.com

          Comment

          • Mike Gleason jr Couturier

            #6
            Re: @&quot;string&q uot;

            Ok thanks guys...

            I was seeing the @ when declaring connection strings in books... (web
            projetcs, web.config)

            Thanks!


            Comment

            • Miro

              #7
              Re: @&quot;string&q uot;

              You should also read up on
              "SQL Injections"... just google it up

              It will give you good examples of why the @ is used as a parameter.


              "Mike Gleason jr Couturier" <nospam@invalid host.comwrote in message
              news:OL51DOS4IH A.1196@TK2MSFTN GP05.phx.gbl...
              Ok thanks guys...
              >
              I was seeing the @ when declaring connection strings in books... (web
              projetcs, web.config)
              >
              Thanks!
              >

              Comment

              • Garfilone

                #8
                Re: @&quot;string&q uot;

                On Jul 8, 9:55 pm, "Mike Gleason jr Couturier"
                <nos...@invalid host.comwrote:
                Why do I see a @ preceding strings in code examples?
                >
                What does the @ do?
                >
                thanks!
                with this symbol you could go without escape chars, for example

                without @: var str="e:\\folder 1\\folder2\\fol der3\\file"

                with @: var str=@"e:\folder 1\folder2\folde r3\file"

                Comment

                Working...