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

前端 未结 9 1429
一整个雨季
一整个雨季 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:52

    This is a verbatim string, and changes the escaping rules - the only character that is now escaped is ", escaped to "". This is especially useful for file paths and regex:

    var path = @"c:\some\location";
    var tsql = @"SELECT *
                FROM FOO
                WHERE Bar = 1";
    var escaped = @"a "" b";
    

    etc

提交回复
热议问题