developer tip

문자열 배열 초기화 옵션

optionbox 2020. 9. 16. 07:36
반응형

문자열 배열 초기화 옵션 [중복]


이 질문에 이미 답변이 있습니다.

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];

MSDN은 이것에 대해 스키니가 있습니다.

참고 URL : https://stackoverflow.com/questions/1504871/options-for-initializing-a-string-array

반응형