C# 程式以字串形式連線單詞


宣告一個字串並新增元素 −

string[] str = { "One", "Two", "Three", "Four", "Five" };

使用 Join() 方法連線單詞 −

string res = string.Join(" ", str);

讓我們來看看完整的程式碼 −

示例

 即時演示

using System;

public class Demo {
   public static void Main() {
      string[] str = { "One", "Two", "Three", "Four", "Five" };
      // join words
      string res = string.Join(" ", str);
      Console.WriteLine(res);
   }
}

輸出

One Two Three Four Five

更新於:22-06-2020

195 次瀏覽

開啟你的職業生涯

透過完成課程獲得認證

開始
廣告
© . All rights reserved.