Locked @ symbol

  • Tuesday, February 28, 2012 3:02 PM
     
     

    Hi,

    I've inherited a C# project from a colleague who has left the company. I note that he sometimes has this declared:
    public const string LOG_PATH = @"CHEMLIBRARY";

    and at other times:
    public const string SILVER = "Ag";

    What does the "AT" symbol, @, do? They seem, as far as I can tell, to be interchangeable so was wondering what this is. Come from a C++ background myself so quite new to C#.

    Thanks,
    Alain

All Replies

  • Tuesday, February 28, 2012 3:20 PM
     
     Proposed Answer

    It stops the processing of escape sequences, such as \.  Here is a reference that includes what the @ symbol is for:

    http://msdn.microsoft.com/en-us/library/362314fe(v=vs.71).aspx


    It would be greatly appreciated if you would mark any helpful entries as helpful and if the entry answers your question, please mark it with the Answer link.

  • Tuesday, February 28, 2012 3:32 PM
     
     

    Aah, ok, simple enough.

    I'm sending this via Outlook Express using a NNTP bridge, not with a web browser. I'm not sure what you mean by "mark any helpful entries", but I'll gladly do that.
    Thanks,
    Alain

    <TSoftware> wrote in message news:64cbc224-67f1-479e-826c-c021ef579937@communitybridge.codeplex.com...

    It stops the processing of escape sequences, such as \. Here is a reference that includes what the @ symbol is for:

    http://msdn.microsoft.com/en-us/library/362314fe(v=vs.71).aspx


    It would be greatly appreciated if you would mark any helpful entries as helpful and if the entry answers your question, please mark it with the Answer link.

  • Tuesday, February 28, 2012 3:34 PM
     
     

    If you log on to the forums on the web site, you will see the the links. Below is a link to this specific question.

    http://social.msdn.microsoft.com/Forums/en-US/csharplanguage/thread/dd0fe57d-fa58-49ce-af2c-b5fce0ffc4cd


    It would be greatly appreciated if you would mark any helpful entries as helpful and if the entry answers your question, please mark it with the Answer link.

  • Tuesday, February 28, 2012 3:48 PM
     
     Proposed Answer Has Code

    Hi,

    In C#, a verbatim string literal starts with @ and is enclosed in double quotation marks. For instance:

    @"Hello World"  // a verbatim string literal

    The advantage of verbatim strings is that escape sequences are not processed, which makes it easy to write, for example, a fully qualified file name:

    @"C:\folder\file.txt" // a verbatim string literal

    Rather than:

    "C:\\folder\\file.txt" // string literal

    At compile time, a verbatim string is converted to ordinary string with all the same escape sequences.

    Since verbatim strings are converted at compile time, there is no impact on the execution of the application in term of memory or performance.

    If you see a verbatim string in the debugger watch window, you will see the escape characters that were added by the compiler, not the verbatim version from your source code.

    For example, the verbatim string:

    @"C:\folder\file.txt"

    will appear in the watch window as:

    "C:\\folder\\file.txt" 

    And just another tip. In C#, to include a double quotation mark in a verbatim string, you need to double it:

    @"""Hello World"""

    will appear as follow:

    "Hello World"

    I hope that this explanation helps you to understand the @ that your colleague has let in code.

    Kind regards,




    My blog

    Whether you’re a construction worker, a forum moderator, or just someone that likes helping people. I think these guidelines can be helpful in keeping you helpful when being helpful.

  • Tuesday, February 28, 2012 4:49 PM
     
     

    Merci, nice and clear.
    Alain

    <Link.fr> wrote in message news:7e51c1ac-b4a0-4d6c-a792-6a88e271c029@communitybridge.codeplex.com...

    Hi,
    In C#, a verbatim string literal starts with @ and is enclosed in double quotation marks. For instance:

    @"Hello World"    // a verbatim string literal

    The advantage of verbatim strings is that escape sequences are not processed, which makes it easy to write, for example, a fully qualified file name:

    @"C:\folder\file.txt" // a verbatim string literal

    Rather than:

    "C:\\folder\\file.txt" // string literal

    At compile time, a verbatim string is converted to ordinary string with all the same escape sequences.

    Since verbatim strings are converted at compile time, there is no impact on the execution of the application in term of memory or performance.

    If you see a verbatim string in the debugger watch window, you will see the escape characters that were added by the compiler, not the verbatim version from your source code.
    For example, the verbatim string:

    @"C:\folder\file.txt"

    will appear in the watch window as:

    "C:\\folder\\file.txt"

    And just another tip. In C#, to include a double quotation mark in a verbatim string, you need to double it:

    @"""Hello World"""

    will appear as follow:

    "Hello World"

    I hope that this explanation helps you to understand the /@/ that your colleague has let in code.

    Kind regards,












    My blog <http://aelassas.free.fr>

    Whether you're a construction worker, a forum moderator, or just someone that likes helping people. I think theseguidelines <http://mikbe.tk/2012/01/16/how-to-answer-a-question-on-the-internet/> can be helpful in keeping you helpful when being helpful.

  • Wednesday, February 29, 2012 8:08 AM
    Moderator
     
     

    Hi Alain,

    Welcome to the MSDN forum.

    It sounds like you have got the answer already. If you are convenient, please mark the reply you think helpful or correct as answer.

    Have a nice day.

    Best Regards,


    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us