c#字符串文字的混淆

时间:2016-11-25 00:09:36

标签: c# literals

我正在编写一个程序,我指的是一个包含文件路径的变量。当我像这样分配变量时:

string strFile = @"\\server\share\restOfPath\file.txt";

我认为它会因为显示而出现,因为" @"在变量的开头。相反,这是我将它显示到控制台时的结果:

\\\\server\\share\\restOfPath\\file.txt

我开始研究并从MSDN中找到了这个页面,它支持我的想法,它应该在我放入时出现,但它仍然带有反斜杠加倍。 https://msdn.microsoft.com/en-us/library/aa691090(v=vs.71).aspx 有人请帮助我理解为什么会发生这种情况

1 个答案:

答案 0 :(得分:1)

using System;

namespace ConsoleApplication5
{
    class Program
    {
        static void Main(string[] args)
        {
            string strFile = @"\\server\share\restOfPath\file.txt";
            Console.WriteLine(strFile);
        }
    }
}

这是输出\ server \ share \ restOfPath \ file.txt