初学VS2010遇到的(/)无法识别的转义序列问题

无法识别的转义序列
在 string 中反斜杠 (/) 的后面是一个意外的字符。编译器需要一个有效的转义符;有关更多信息,请参见字符转义。
下面的示例生成 CS1009:
// CS1009-a.cs
class MyClass
{
   static void Main()
   {
      string a = "/m";   // CS1009
      // try the following line instead
      // string a = "/t";
   }
}
发生该错误的原因通常是在文件名中使用了反斜杠字符,例如:
string filename = "c:/myFolder/myFile.txt";
若要纠正该错误,请使用“//”或前面带有 @ 且用引号括起的字符串,如下面的示例所示:
// CS1009-b.cs
class MyClass
{
   static void Main()
   {
      string filename = "c:/myFolder/myFile.txt";   // CS1009
      // try the one of the following lines instead
      // string filename = "c://myFolder//myFile.txt";
      // string filename = @"c:/myFolder/myFile.txt";
   }
}

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值