Options for initializing a string array

mrblah picture mrblah · Oct 1, 2009 · Viewed 156.8k times · Source

What options do I have when initializing string[] object?

Answer

Will Eddins picture Will Eddins · Oct 1, 2009

You have several options:

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