기초 메모지

C# - 제네릭 컬렉션 - 딕셔너리(Dictionary) 본문

Languages/C#

C# - 제네릭 컬렉션 - 딕셔너리(Dictionary)

라큐브 2022. 6. 30. 11:43

딕셔너리(Dictionary)는 Key, Value Pair 형태를 가지고 있습니다. 

딕셔너리의 특성은 아래와 같습니다.

 

1. 선언 시 Key 타입과, Value 타입을 받습니다.

// Key, Value Pair 형식으로 Key 타입, Value 타입을 받고 있습니다.
Dictionary<string, string> dic = new Dictionary<string, string>();

 

  

 

2. Key는 고유한 값으로 중복될 수 없습니다.

dic.Add("Key A", "Value A");
// 중복된 키 삽입 시 에러 발생.
dic.Add("Key A", "Value B");

3. 인덱스로 Key를 받아 Pair Value를 반환 합니다.

Console.WriteLine(dic["Key A"]);
// Value A

 

반응형
Comments