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. Use of @ in a variable name

Use of @ in a variable name

Scheduled Pinned Locked Moved C#
question
9 Posts 6 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.
  • S Offline
    S Offline
    sa_runner
    wrote on last edited by
    #1

    Is there any significance to the use of the @ in a variable name (like @intx)? Thanks.

    N P U G 4 Replies Last reply
    0
    • S sa_runner

      Is there any significance to the use of the @ in a variable name (like @intx)? Thanks.

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      The @ symbol is usually used for SQL Server parameters SqlCommand.Parameters["@ID"].Value = 1234; CREATE PROC sp_MyProc @ID INT AS SELECT * FROM Table WHERE ID = @ID The at symbol is also used to escape string literals string path = @"C:\Program Files\Some Folder";


      only two letters away from being an asset

      1 Reply Last reply
      0
      • S sa_runner

        Is there any significance to the use of the @ in a variable name (like @intx)? Thanks.

        P Offline
        P Offline
        Pete OHanlon
        wrote on last edited by
        #3

        sa_runner wrote:

        Is there any significance to the use of the @ in a variable name (like @intx)?

        Using @ means that you can have a variable name that (sort of) matches a type name, e.g. object @object. In your code you can then refer to @object. It really doesn't seem to be good practice to me.

        Deja View - the feeling that you've seen this post before.

        1 Reply Last reply
        0
        • S sa_runner

          Is there any significance to the use of the @ in a variable name (like @intx)? Thanks.

          U Offline
          U Offline
          Urs Enzler
          wrote on last edited by
          #4

          In SQL yes, in C# no. You can use it in c# as well, but the only thing that happens is that Intellisense does not work on this variable :-)

          -^-^-^-^-^- no risk no funk ................... please vote ------>

          1 Reply Last reply
          0
          • S sa_runner

            Is there any significance to the use of the @ in a variable name (like @intx)? Thanks.

            G Offline
            G Offline
            Guffa
            wrote on last edited by
            #5

            @ is used to specify an identifier. It's mostly used to access members of third party classes that happen to be keywords in C#. Example: SomeComponent.@int x = new SomeComponent.@int();

            --- single minded; short sighted; long gone;

            N 1 Reply Last reply
            0
            • G Guffa

              @ is used to specify an identifier. It's mostly used to access members of third party classes that happen to be keywords in C#. Example: SomeComponent.@int x = new SomeComponent.@int();

              --- single minded; short sighted; long gone;

              N Offline
              N Offline
              Not Active
              wrote on last edited by
              #6

              Interesting, learn something all the time. Can't say as I've every seen this in use, and can't think of a reason why.


              only two letters away from being an asset

              D 1 Reply Last reply
              0
              • N Not Active

                Interesting, learn something all the time. Can't say as I've every seen this in use, and can't think of a reason why.


                only two letters away from being an asset

                D Offline
                D Offline
                Dan Neely
                wrote on last edited by
                #7

                reserved words are different in different languages. It's needed to allow assemblies written in Foo.net to always work in Bar.net without requiring any changes to the Foo.net source code because the author used a variable name that's reserved in Bar.net. MS tries to avoid any situation like this for the languages they officially provide (I've never actually seen it used myself), but the more languages supported the harder it becomes, and 3rd parties don't always have the same degree of foresight into cross language issues. This is an officially sanctioned work around.

                -- If you view money as inherently evil, I view it as my duty to assist in making you more virtuous.

                N 1 Reply Last reply
                0
                • D Dan Neely

                  reserved words are different in different languages. It's needed to allow assemblies written in Foo.net to always work in Bar.net without requiring any changes to the Foo.net source code because the author used a variable name that's reserved in Bar.net. MS tries to avoid any situation like this for the languages they officially provide (I've never actually seen it used myself), but the more languages supported the harder it becomes, and 3rd parties don't always have the same degree of foresight into cross language issues. This is an officially sanctioned work around.

                  -- If you view money as inherently evil, I view it as my duty to assist in making you more virtuous.

                  N Offline
                  N Offline
                  Not Active
                  wrote on last edited by
                  #8

                  That explains it, thanks.


                  only two letters away from being an asset

                  S 1 Reply Last reply
                  0
                  • N Not Active

                    That explains it, thanks.


                    only two letters away from being an asset

                    S Offline
                    S Offline
                    sa_runner
                    wrote on last edited by
                    #9

                    I appreciate all the answers. Thanks.

                    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