C# 中字符串字面值中的 @ 前缀有什么作用?


@ 前缀表示在该符号后面的字符串中不必转义特殊字符。

以下声明

@"D:
ew"

等同于

"D:\
ew"

如果要使用大型字符串并希望它跨多行显示,也可以使用 @ 前缀。以下是一个显示多行字符串的示例 −

示例

 实时演示

using System;

namespace Demo {

   class Program {

      static void Main(string[] args) {
         string str = @"Welcome User,
         Kindly wait for the image to
         load";

         Console.WriteLine(str);
      }
   }
}

输出

Welcome User,
Kindly wait for the image to
load

更新于:20-6-2020

617 次浏览

开启您的 职业生涯

通过完成课程获得认证

开始
广告
© . All rights reserved.