[c#] Dictionary practice3

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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication8
{
    class Program
    {
        static void Main(string[] args)
        {
            Dictionary<stringint> moneyInfo = new Dictionary<stringint>();
            moneyInfo.Add("KIM"1000);
            moneyInfo.Add("LEE"2000);
            moneyInfo.Add("SIN"3000);
            moneyInfo.Add("JOO"4000);
            moneyInfo.Add("SON"5000);
            foreach (KeyValuePair<string,int> a in moneyInfo)
            {
                Console.WriteLine("Name:{0}, Money:{1}", a.Key, a.Value);
            }
            /******************************/
            /* 특정 key의 value 조회 */
            /******************************/
            Console.WriteLine("value 조회-Money:{0}", moneyInfo["KIM"]);
            /******************************/
            /* 특정 key의 value 변경 */
            /******************************/
            Console.WriteLine("value 변경-Money:{0}", moneyInfo["KIM"+ 500);
            /******************************/
            /* 특정 key 조회 */
            /******************************/
            if (moneyInfo.ContainsKey("JIN"== false)
            {
                Console.WriteLine("해당 KEY는 없습니다");
            }
            else
            {
                Console.WriteLine("해당 KEY는 있습니다");
            }
            /******************************/
            /* 특정 value 조회 */
            /******************************/
            if (moneyInfo.ContainsValue(2000== false)
            {
                Console.WriteLine("해당 VALUE는 없습니다");
            }
            else
            {
                Console.WriteLine("해당 VALUE는 있습니다");
            }
            
            Console.ReadLine();
        }
    }
}
cs

댓글

이 블로그의 인기 게시물

[c#] DataTable을 dataGridView에 바인딩

[React] index.html 수정하기

[React] 프로젝트 생성