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 次瀏覽

開啟您的 職業生涯

透過完成課程獲得認證

開始
廣告