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

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

    Putting a @ in front of a string enables you to use special characters such as a backslash or double-quotes without having to use special codes or escape characters.

    So you can write:

    string path = @"C:\My path\";
    

    instead of:

    string path = "C:\\My path\\";
    

提交回复
热议问题