在C#中,有多種方法可以創建一個String數組。以下是其中的幾種方法:
string[] array = { "apple", "banana", "orange" };
string[] array = new string[3];
array[0] = "apple";
array[1] = "banana";
array[2] = "orange";
string[] array = Array.CreateInstance(typeof(string), 3) as string[];
array[0] = "apple";
array[1] = "banana";
array[2] = "orange";
string str = "apple,banana,orange";
string[] array = str.Split(',');
string[] fruits = { "apple", "banana", "orange" };
string[] array = (from fruit in fruits
where fruit.Length > 5
select fruit).ToArray();
這些都是創建String數組的常用方法,可以根據具體的需求選擇合適的方法。