@ symbol and double quotation marks

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cyhcyhhychyc
    New Member
    • Dec 2009
    • 8

    @ symbol and double quotation marks

    string str = @""";
    string str = """;
    Both of them are syntactically wrong. But I dont exactly know why.
    How does the compiler/interpreter process the two definitions above?
    when the compiler encounters [@"], whether will it jump to the end of the code line to find [;] or just process the line left to right?
  • ssnaik84
    New Member
    • Aug 2009
    • 149

    #2
    compiler first check semi-colon (;) that is terminator symbol of statement.
    then takes value in between first two double quote (")

    if you want to use extra double quotes, then use backward slash (\) before extra double quote (")

    Code:
    string str = "\"\"";

    Comment

    • cyhcyhhychyc
      New Member
      • Dec 2009
      • 8

      #3
      Thanks.But I dont agree with u fully.For[string str = """;], compiler seems to check semi-colon to find the end position of the code line. But for [string str = @""";],due to the At sign, this code line in VS2005 together with several other code lines below are all turned to red(red color means syntactically wrong in VS2005 IDE).
      Obviously, compiler consider [string str = @""";] and several lines below it to be a single line,and the fire semi-colon( that's the one in[ @""";]) is considered to be a normal char. That's why @ confused me. It seems that "@" doesn't know how to deal with the string follows him when the string contains extra double quotes.

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        Using the @ sign in C# tells the compiler to ignore any string escape sequences. So using \r\n or \t or \" will no longer work. I believe it is only in C#
        The double " I think is only in VB(NET)

        C# example
        [code=c#]
        string mydir = @"c:\temp\";
        string samedir ="c:\\temp\\ ";
        //both are correctly escaped
        [/code]

        Comment

        Working...