닷넷,C#,.NET
C#/.NET Dictionary 콜렉션 인자 추가(Add) 및 삭제(Remove)
꿈만은공돌
2018. 4. 24. 21:46
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); }