string[]
オブジェクトを初期化するとき、どのようなオプションがありますか?
いくつかのオプションがあります:
string[] items = { "Item1", "Item2", "Item3", "Item4" };
string[] items = new string[]
{
"Item1", "Item2", "Item3", "Item4"
};
string[] items = new string[10];
items[0] = "Item1";
items[1] = "Item2"; // ...
基本:
string[] myString = new string[]{"string1", "string2"};
または
string[] myString = new string[4];
myString[0] = "string1"; // etc.
高度:リストから
list<string> = new list<string>();
//... read this in from somewhere
string[] myString = list.ToArray();
StringCollectionから
StringCollection sc = new StringCollection();
/// read in from file or something
string[] myString = sc.ToArray();
string[] str = new string[]{"1","2"};
string[] str = new string[4];