C#에 컬렉션 중 하나인 Dictionary 이다.
아래 예제는 인자 추가(Add()) 및 삭제(RemoveAt()) 관한 내용이다.
using System.Collections.Generic;
var dict = new Dictionary<int, String>();
dict.Add(1, "one");
dict.Add(2, "two");
dict.Add(3, "three");
Console.WriteLine("----------1----------");
foreach (KeyValuePair<int, string> item in dict)
{
Console.WriteLine(item.Key + " " + item.Value);
}
Console.WriteLine("----------2----------");
dict.Remove(2); //key값이 2인 두번째 인자 삭제
foreach (KeyValuePair<int, string> item in dict)
{
Console.WriteLine(item.Key + " " + item.Value);
}
'닷넷,C#,.NET' 카테고리의 다른 글
| C#/.NET readonly vs const 예제로 보는 차이점 (0) | 2018.05.06 |
|---|---|
| C#/.NET 가비지 컬렉션의 메모리 할당 및 해제 기본 원리 (Garbage collection) (0) | 2018.05.02 |
| C#/.NET 컬렉션 리스트(List) 추가, 삭제, 삽입 예시 (0) | 2018.04.24 |
| C# 정규식을 사용하여 패턴 매칭(Regex, IsMatch) (5) | 2018.04.24 |
| C#/.NET String 사용, Length, Split , Substirng, IndexOf,Trim, Contains, StartsWith (0) | 2018.04.23 |


