Dictionary Ű ϴ ÷̴. ؽ ˰ Ͽ ؽ ̶̺ θ 踦 ǥѴٰ ؼ ̶ θ. ʺ ˻ Ưȭ ڷᱸ ˻ ӵ ȯ . ﰳ Ű ־ ǽð ãƳ. ڴ .
Dictionary<TKey,TValue>()
Dictionary<TKey,TValue>(Int32)
Dictionary<TKey,TValue>(IDictionary<TKey,TValue>)
Dictionary<TKey,TValue>(IEqualityComparer<TKey>)
ڴ Ű Ÿ ϴ TKey Ÿ ϴ TValue Ÿ μ . Ű, Ÿ ִ. Ű ڿ, Dictionary<String, int> Ÿ Ѵ.
Ʈ ڸ ص ϴ. 뷮 ڵ þ ̸ 뷮 ִ. ٸ ϴ ڵ ǵǾ ִ. Ű ϴ ڸ ֵ ҹڸ ϴ ⺻ ڸ Ѵ.
߰ Add 峪 [] ε Ѵ. Add Ű μ ϰ ε Űκ Ҹ ã Ѵ.
Add (TKey key, TValue value);
this[key] = value
ο Ű ϴ ̹ Ű ó ٸ. Add ArgumentException ܸ Ű ε ߺŰ ο üѴ. Add ߰ ϰ ε Ű ߰, Ѵ.
ؾ ϸ null . ݸ Ÿ null̾ ߺ ϴ. д ǵǾ ε Ѵ. [ ] ȣȿ Ű ϸ о Ѵ. Ű KeyNotFoundException ܰ Ѵ.
class CSTest {
static void Main()
{
Dictionary<String, String> dic = new Dictionary<String, String>();
dic.Add("ѱ", "");
dic["߱"] = "";
try
{
dic.Add("ѱ", "λ");
}
catch (ArgumentException)
{
Console.WriteLine("̹ Դϴ.");
}
dic["߱"] = "¡";
dic.Add("Ϻ", "");
Console.WriteLine(dic["ѱ"]);
Console.WriteLine(dic["߱"]);
Console.WriteLine(dic["Ϻ"]);
}
}
̹ Դϴ.
¡
ѱ Ű ̹ Ǿ ִ ¿ Add ѱ ߰ϸ ܰ Ѵ. ݸ ߱ Ű ̹ ִ ¿ ε ٽ ϸ ٲ. ϰ Ű б ϴ ˻ؾ Ѵ.
bool ContainsKey (TKey key);
bool ContainsValue (TValue value);
ContainsKey Ű ϴ Ѵ. 尡 true ϸ ش Ű ̹ ϴ ̴. ε Ű ϰ Add Ű ؼ ȵȴ.
ContainsValue ϴ Ѵ. Ű ؽ ˰ ãµ ˻ ãƾ ϹǷ ӵ .
class CSTest {
static void Main()
{
Dictionary<String, String> dic = new Dictionary<String, String>();
dic.Add("ѱ", "");
dic["߱"] = "¡";
dic.Add("Ϻ", "");
if (dic.ContainsKey("ѱ"))
{
Console.WriteLine("ѱ : " + dic["ѱ"]);
}
if (dic.ContainsKey("̱"))
{
Console.WriteLine("̱ : " + dic["̱"]);
}
if (dic.ContainsValue("¡"))
{
Console.WriteLine("¡ ");
}
if (dic.ContainsValue(""))
{
Console.WriteLine(" ");
}
}
}
ѱ :
¡
ѱ Ű ־ ̱ Ű ʴ´. Ű ܰ Ѵ. Ű ִ о ϴ. ¡ .
ϴ ִ, Ű . Űκ żϰ ã ڷ ݴ ƴϴ. κ Ű ã ȸϸ ϴ ۿ .
б Ű θ ˻ϴ ̴. ٰ Ű δ ˻ ܰ ־ ϴ. ܾ ã 带 ȣѴ.
bool TryGetValue (TKey key, out TValue value);
Ű μ ϰ true Ѵ. Ű μ ⺻ ϰ false Ѵ.
class CSTest {
static void Main()
{
Dictionary<String, String> dic = new Dictionary<String, String>();
dic.Add("ѱ", "");
dic["߱"] = "¡";
dic.Add("Ϻ", "");
String country;
if (dic.TryGetValue("Ϻ", out country))
{
Console.WriteLine("Ϻ : " + country);
}
if (dic.TryGetValue("", out country))
{
Console.WriteLine(" : " + country);
}
else
{
Console.WriteLine(" ");
}
}
}
Ϻ :
TryGetValue Ϻ ˻ϸ country 츦 ϰ true Ѵ. ̶ ε ٽ dic["Ϻ"] ã ʿ country ٷ ϸ ȴ. ˻ϸ country null ϰ false Ѵ. μ ϴ ƴ϶ ⺻ .
TryGetValue ϰ θ ˷ ܸ Ű ʾ ۼ ʾƵ ȴ. ¿ μ ̸ غϰ ϰ Ѵٴ 鿡 ŷӱ Ѱ̴.
Ű 带 Ѵ.
bool Remove (TKey key);
void Clear ();
Ű ߰Ͽ true ϰ Ű false Ѵ. ص ܴ ȭ ȴ. Clear Ҹ . Count 0 뷮 ȭ .
Ҹ ȸϸ foreach ϴ. Ҵ KeyValuePair<TKey,TValue> Ÿ̸ Ÿ Ҹ Ű ϳ д´. Ű Ѵ.
class CSTest {
static void Main()
{
Dictionary<String, String> dic = new Dictionary<String, String>();
dic.Add("ѱ", "");
dic["߱"] = "¡";
dic.Add("Ϻ", "");
foreach (KeyValuePair<String, String> item in dic)
{
Console.WriteLine(item.Key + " : " + item.Value);
}
}
}
ѱ :
߱ : ¡
Ϻ :
Ÿ ̸ var Ƽ ص ȴ. ȸ б⸸ ϸ Ҹ . item Key Value б Ӽ̾ . ٸ ڵ ?
foreach (KeyValuePair<String, String> item in dic)
{
dic[item.Key] = "";
}
ε item.Key о ش Ű ϰ Ͽ. ̻ ƴϸ ܰ Ѵ. foreach dic ȸϴ ߰ dic ٲ ȸ ƾ ̴.
Ӹ ƴ϶ ÷ ȸ߿ б⸸ ؾ Ѵ. foreach GetEnumerator ڸ ٸ . Ӽ .
Ӽ |
|
Count |
ϴ б ̴. 뷮 ٴ ϴ . |
Keys |
Ű ÷̸ Dictionary<TKey,TValue>.KeyCollection Ÿ̴. |
Values |
÷̸ Dictionary<TKey,TValue>.ValueCollection Ÿ̴. |
Comparer |
Ű ϴ IEqualityComparer<TKey> Ÿ ü̴. |
ü ȸϴ Keys Values ȸ . Comparer Ű ߺ ˻ϴ ̸ Ʈ EqualityComparer<T>.Default ϰ Ǿ ִ. ؼ 幰 ڿ Ÿ Ű ҹ о Ѵ. .
class CSTest {
static void Main()
{
Dictionary<String, String> dic = new Dictionary<String, String>();
dic.Add("Korea", "");
dic.Add("KOREA", "");
if (dic.ContainsKey("korea"))
{
Console.WriteLine("ѱ ");
}
else
{
Console.WriteLine("ѱ ");
}
}
}
ѱ
Korea KOREA Ű ߴµ ȴ. Ʈ ڰ ҹڸ ϱ öڴ Ƶ ٸ Ű ߺ ʴ´. ¿ korea Ű ִ ã ٰ ´.
ҹڸ Ȯ ؾ ϴ ̷ մ ڵ尪̳ URL ҹ . www.soen.kr www.SoEn.kr ã ٰ ´.
̷ ҹڸ ϴ StringComparer.OrdinalIgnoreCase ڷ ؾ Ѵ. ڴ ϴ ̾ ߰ ٲ ִ.
class CSTest {
static void Main()
{
Dictionary<String, String> dic = new Dictionary<String, String>
(StringComparer.OrdinalIgnoreCase);
dic.Add("Korea", "");
//dic.Add("KOREA", "");
if (dic.ContainsKey("korea"))
{
Console.WriteLine("ѱ ");
}
else
{
Console.WriteLine("ѱ ");
}
}
}
ѱ
ڰ ҹڸ ϸ KoreaŰ ¿ KOREA ߺ̾ . korea ãƵ ִٰ Ѵ. Ű ڿ̶⺸ٴ ĺڿ ҹڸ ϴ ︮ 찡 .
ڴ Ű ϴ Ҹ ҹ ٲ ʴ´. Ű ⺻ ڷ Ѵ.
class CSTest {
static void Main()
{
Dictionary<String, String> dic = new Dictionary<String, String>
(StringComparer.OrdinalIgnoreCase);
dic.Add("Korea", "Seoul");
dic.Add("CHINA", "BEIJING");
dic.Add("japan", "Tokyo");
foreach (KeyValuePair<String, String> item in dic)
{
Console.WriteLine(item.Key + " : " + item.Value);
}
Console.WriteLine(dic.ContainsValue("seoul") ? "ִ." : ".");
}
}
Korea : Seoul
CHINA : BEIJING
japan : Tokyo
.
Ű Է ҹڴ ״ ȴ. ڰ ҹڸ ص ã ҹڸ Ѵ. seoul Seoul ִ. ҹ о Ϸ 빮ڳ ҹڷ ٲ ־ Ѵ.
SortedDictionary<TKey,TValue> Ÿ Ҹ Ͽ ˻ Ѵ. ˰ Ž ٸ. 뷮 ӵ 뷮 Dictionary .
õ SoEn wedisk
김대중컨벤션센터역채팅
청주출장샵 군산출장샵 의왕출장마사지
해외토토사이트
덕월동마사지
꿀TV
남원출장만남✓군포출장샵✓인천출장안마
출장여대생 | 상주출장샵상 | 경산콜걸샵
보도방후기✓정읍출장마사지✓서산출장만남
인천출장마사지✓노원출장만남✓양주출장만남
영통구출장샵 미세먼지마스크
언스위트 망가
섹
삼척시출장마사지 피부
부산콜걸 부동산
재택부업 알바
주부재택알바 | 재택근무 운영 매뉴얼 | 가상화폐세금
라이브재테크더바더꽃제이
일당알바✓우리은행 ppl✓sbi저축은행 노원지점
꽃구경
소액재테크
직장
부업 수익 알바추천 집에서 부업
여름나기
연남동카페
라텍스스타킹
김포출장안마
병아리의 알
후타나리 번역
엘지웹하드
|