Why use @ when declaring strings

Posted on 2006-06-06
Last Modified: 2012-05-05
I have come across some code that uses @ when declaring a string.  I'm curious, can anyone tell me why you would want to do this?  For example, I've seen:

string finalPath = @"\\agentdev\agyroot\common\tempUpload\NCQ\";

Why not just do:

string finalPath = "\\agentdev\agyroot\common\tempUpload\NCQ\";

Question by:russomr
    LVL 142

    Assisted Solution

    by:Guy Hengel [angelIII / a3]
    with @ the \ are not considered to be escape characters
    LVL 4

    Accepted Solution

    @-quoting  allows for the escape sequences not to be processed,
    these are escape sequences:
    \' Single quote
    \" Double quote
    \\ Backslash
    \nnn Octal number (nnn)
    \0 Null character (really just the octal number zero)
    \a Audible bell
    \b Backspace
    \f Formfeed
    \n Newline
    \r Carriage return
    \t Horizontal tab
    \v Vertical tab
    \xnnn Hexadecimal number (nnn)

    So in order to have this string "\\agentdev\agyroot\common\tempUpload\NCQ\"
    one has two options:

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
    ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    This video discusses moving either the default database or any database to a new volume.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now