在 C# 中如何定義多行字串文字?


假設字串是 −

Welcome User, Kindly wait for the image to load

對於多行字串文字,首先使用 @ 字首將其像以下語句一樣進行設定 −

string str = @"Welcome User,
Kindly wait for the image to
load";

現在讓我們顯示結果。該字串現在是一個多行字串 −

示例

 線上演示

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

968 次瀏覽

開啟您的職業生涯

完成課程即可獲得認證

開始
廣告
© . All rights reserved.