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-Jun-2020

616 檢視數

啟動您的 職業生涯

完成課程以獲得認證

開始
廣告