'removeat'에 해당되는 글 1건

  1. 2018.04.24 C#/.NET Dictionary 콜렉션 인자 추가(Add) 및 삭제(Remove)


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);
}


Posted by 꿈만은공돌
,