在C#中,可以将字符串用作字符数组,但是,更常见的做法是使用string关键字声明字符串变量。string关键字是System.String类的别名。
声明一个空字符串。
string[] arr = new string[] {}; // empty string现在让我们看看当打印此空字符串时会发生什么。
using System;
namespace Demo {
class Program {
static void Main(string[] args) {
string[] arr = new string[] {}; // empty string
string res = String.Join(" ", arr);
//现在让我们打印空字符串
Console.WriteLine("This won't print any message since its an empty string {0}", res);
}
}
}输出结果
This won't print any message since its an empty string