C# 程序将单词合并为一个字符串

csharpprogrammingserver side programming更新于 2025/9/17 14:52:00

声明一个字符串并添加元素 −

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" };
      // 连接单词
      string res = string.Join(" ", str);
      Console.WriteLine(res);
   }
}

输出

One Two Three Four Five

相关文章