文字列配列を初期化するためのオプション [重複] 質問する

文字列配列を初期化するためのオプション [重複] 質問する

オブジェクトを初期化するときにはどのようなオプションがありますかstring[]?

ベストアンサー1

いくつかのオプションがあります:

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"; // ...

おすすめ記事