Yang.공부방

Dictionary<TKey,TValue>Class (네임스페이스 : System.Collections.Generic)

: 값을 키와 함께 받아 HashTable에 저장한다. 

: 키 값을 통해 데이터를 빠르게 검색 가능(키 값에 따라 검색 속도는 다르다)

: Add를 사용하여 키와 값을 저장


TKey : 사전에 있는 키의 형식

TValue : 사전에 있는 값의 형식


상속 : Object -> Dictionary<TKey,TValue>

파생 : System.ServiceModel.MessageQuerySet


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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Test_01
{
    class Program
    {
        static void Main(string[] args)
        {
            Dictionary<stringstring> Test = new Dictionary<stringstring>();
 
            Test.Add("key""value");
            Test.Add("양재""공부좀해");
            Test.Add("코딩""잘하고싶다");
            //요소 추가
 
            try
            {
                Test.Add("txt""winword.exe");
            }
            catch(ArgumentException)
            {
                Console.WriteLine("an element with Key = \"txt\" already exists.");
            }
            // 중복키일 경우 ArgumentException 발생
 
            Console.WriteLine("for key = \"코딩\", value = {0}.", Test["코딩"]);
            //출력 : for key = 코딩, value = 잘하고싶다
            
        }
    }
}
 
cs


'C# > 과제' 카테고리의 다른 글

속성  (0) 2019.04.03
[Collection]ArrayList  (0) 2019.04.01
//미완// Collection[컬렉션]  (0) 2019.03.31
Boxing 및 Unboxing  (0) 2019.03.29
(3.25) 몬스터 공격하기 ver.수정  (0) 2019.03.26