반응형
문자열 배열 초기화 옵션 [중복]
이 질문에 이미 답변이 있습니다.
- 가능한 모든 배열 초기화 구문 13 답변
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];
참고 URL : https://stackoverflow.com/questions/1504871/options-for-initializing-a-string-array
반응형
'developer tip' 카테고리의 다른 글
bootRun에서 JVM 옵션을 전달하는 방법 (0) | 2020.09.16 |
---|---|
AngularJS 지시문 요소 메서드 바인딩-TypeError : 'in'연산자를 사용하여 1에서 'functionName'을 검색 할 수 없습니다. (0) | 2020.09.16 |
boolean (물음표 없음)을 반환하는 Java 메서드에 대한 명명 규칙 (0) | 2020.09.16 |
HTML5 : 두 개의 입력이 가능한 슬라이더? (0) | 2020.09.16 |
Razor로 일반 @helper 메서드를 만들 수 있습니까? (0) | 2020.09.16 |