본문 바로가기
백엔드/C#

Dictionary에서 배열값 초기화 하기

by 1005ptr 2018. 5. 10.
반응형

C#에서는 Map을 Dictionary라고 부르는데 생성하고 초기화 할 수가 있다


Dictionary<String, int> test = new Dictionary<string, int>

{

{"a", 1}, {"b", 2}, {"c", 3}

}


근데 배열을 초기화 하려니까

Dictionary<String, int[]> test = new Dictionary<string, int[]>

{

{"a", {1, 2}}, {"b", {2, 3}}, {"c", {3, 4}}

}

이것도 아니고

Dictionary<String, int[]> test = new Dictionary<string, int[]>

{

{"a", [1, 2]}, {"b", [2, 3]}, {"c", [3, 4]}

}

이것도 아니었다


정답은

Dictionary<String, int[]> test = new Dictionary<string, int[]>

{

{"a", new [] {1, 2}}, {"b", new [] {2, 3}}, {"c", new [] {3, 4}}

}


https://stackoverflow.com/questions/38432599/how-to-initialize-an-dictionary-with-an-array-value?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa

반응형

'백엔드 > C#' 카테고리의 다른 글

DataTable을 DataGridView에 DataBinding  (0) 2018.05.11
Form을 하나만 열고 싶을 때  (0) 2018.05.11
Mdi Form / Mdi Child Form  (0) 2018.05.10
Parent/Child DataGridView  (0) 2018.05.10
폼 위치 변경  (0) 2018.05.08

댓글