什麼是 C# 中的字串常量?


字串常量用雙引號 "" 或 @ "" 括起來。字串包含與字元常量相似的字元:普通字元、轉義序列和通用字元。

以下是字串常量的一些示例 −

“Hi, User"
"You’re Welcome, \

以下是顯示如何使用字串常量的示例 −

示例

 即時演示

using System;

namespace Demo {

   class Program {
      static void Main(string[] args) {

         // string
         string str1 ="Hello, World";
         Console.WriteLine(str1);
         // Multi-line string
         string str2 = @"Welcome,
         Hope you are doing great!";
         Console.WriteLine(str2);
      }
   }
}

輸出

Hello, World
Welcome,
Hope you are doing great!

更新日期:20-Jun-2020

329 次瀏覽

開啟你的 職業生涯

完成課程獲得認證

開始
廣告
© . All rights reserved.