Подтвердить что ты не робот

Параметры инициализации массива строк

Какие параметры у меня есть при инициализации объекта string[]?

4b9b3361

Ответ 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"; // ...

Ответ 2

Basic:

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();

Ответ 3

string[] str = new string[]{"1","2"};
string[] str = new string[4];