What's the @ operator do?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • stork

    What's the @ operator do?

    If I see a piece of code like:

    someobject.stri ngProperty = @mycontrol.Text ;

    What does the @ do in that case?

    Is that a clone operator?

  • Peter Duniho

    #2
    Re: What's the @ operator do?

    On Thu, 15 May 2008 09:16:30 -0700, stork <tbandrow@stork yak.comwrote:
    If I see a piece of code like:
    >
    someobject.stri ngProperty = @mycontrol.Text ;
    >
    What does the @ do in that case?
    >
    Is that a clone operator?
    It's hard to say whether that's even valid code. But assuming it is, it's
    indicating to the compiler that the variable "@mycontrol " should not be
    confused with some built-in keyword "mycontrol" .

    Usually you'd only see that in some sort of auto-generated code.
    Hand-written code would normally only use "@" if the variable name did in
    fact conflict with an existing C# keyword.

    Pete

    Comment

    • Alcides

      #3
      Re: What's the @ operator do?

      On May 15, 12:16 pm, stork <tband...@stork yak.comwrote:
      If I see a piece of code like:
      >
      someobject.stri ngProperty = @mycontrol.Text ;
      >
      What does the @ do in that case?
      >
      Is that a clone operator?
      the @ can be used with strings. not sure if can be used with var
      names.
      For strings you can use for @"c:\Docs\Sourc e\a.txt" rather than "c:\
      \Docs\\Source\\ a.txt"

      Al Schulz
      Blogger ist ein Veröffentlichungs-Tool von Google, mit dem du ganz einfach deine Gedanken der Welt mitteilen kannst. Mit Blogger kannst du problemlos Texte, Fotos und Videos in deinem persönlichen Blog oder deinem Team-Blog veröffentlichen.

      Comment

      • .\\\\axxx

        #4
        Re: What's the @ operator do?

        On May 16, 2:16 am, stork <tband...@stork yak.comwrote:
        If I see a piece of code like:
        >
        someobject.stri ngProperty = @mycontrol.Text ;
        >
        What does the @ do in that case?
        >
        Is that a clone operator?
        The prefix "@" enables the use of keywords as identifiers, which is
        useful when interfacing with other programming languages. The
        character @ is not actually part of the identifier, so the identifier
        might be seen in other languages as a normal identifier, without the
        prefix. An identifier with an @ prefix is called a verbatim
        identifier. Use of the @ prefix for identifiers that are not keywords
        is permitted, but strongly discouraged as a matter of style.
        From MSDN

        Comment

        Working...