What's the @ in front of a string in C#?

前端 未结 9 1409
一整个雨季
一整个雨季 2020-11-22 01:04

This is a .NET question for C# (or possibly VB.net), but I am trying to figure out what\'s the difference between the following declarations:

string hello =          


        
9条回答
  •  旧巷少年郎
    2020-11-22 01:36

    It marks the string as a verbatim string literal - anything in the string that would normally be interpreted as an escape sequence is ignored.

    So "C:\\Users\\Rich" is the same as @"C:\Users\Rich"

    There is one exception: an escape sequence is needed for the double quote. To escape a double quote, you need to put two double quotes in a row. For instance, @"""" evaluates to ".

提交回复
热议问题