Using the literal '@' with a string variable

后端 未结 6 764
Happy的楠姐
Happy的楠姐 2020-12-17 01:42

I have a helper class pulling a string from an XML file. That string is a file path (so it has backslashes in it). I need to use that string as it is... How can I use it lik

6条回答
  •  死守一世寂寞
    2020-12-17 02:02

    In C# the @ symbol combined with doubles quotes allows you to write escaped strings. E.g.

    print(@"c:\mydir\dont\have\to\escape\backslashes\etc");
    

    If you dont use it then you need to use the escape character in your strings.

    http://msdn.microsoft.com/en-us/library/aa691090(VS.71).aspx

    You dont need to specify it anywhere else in code. In fact doing so should cause a compiler error.

提交回复
热议问题