如何在 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-Jun-2020

968 檢視

開啟你的職業生涯

透過完成課程獲得認證

開始
廣告
© . All rights reserved.