[c#] Dictionary practice1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
Dictionary<string, int> mydic = new Dictionary<string, int>();
//ADD
mydic.Add("KIM", 1);
mydic.Add("YOU", 2);
mydic.Add("JIN", 3);
//Dictionary를 foreach 로 출력
foreach (KeyValuePair<string,int> a in mydic)
{
Console.WriteLine("key:{0}, value:{1}", a.Key, a.Value);
}
//PRINT VALUE
Console.WriteLine(mydic["KIM"]);
//"YOU" REMOVE
mydic.Remove("YOU");
foreach (KeyValuePair<string, int> a in mydic)
{
Console.WriteLine("key:{0}, value:{1}", a.Key, a.Value);
}
//Dictionary Count
Console.WriteLine(mydic.Count);
System.Console.ReadLine();
}
}
}
| cs |
댓글
댓글 쓰기