반응형

Hashtable 클래스



구문

[SerializableAttribute]
[ComVisibleAttribute(true)]
public class Hashtable : IDictionary, ICollection, IEnumerable, 
	ISerializable, IDeserializationCallback, ICloneable




Hashtable 의 키 값은 숫자도 가능하지만 문자열 및 오브젝트도 동시에 가능합니다
즉 구분이 될 수 있는 것들은 가능하지만, null 은 불가능합니다
또한 해쉬 테이블은 저장되는 순서가 보장되지 않습니다



초기화 하 고 다양 한 기능을 수행 하는 방법을 보여 주는 Hashtable 및 해당 키와 값을 출력 하는 방법입니다.

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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
using System;
using System.Collections;
 
class Example
{
    public static void Main()
    {
        // Create a new hash table.
        //
        Hashtable openWith = new Hashtable();
 
        // Add some elements to the hash table. There are no 
        // duplicate keys, but some of the values are duplicates.
        openWith.Add("txt""notepad.exe");
        openWith.Add("bmp""paint.exe");
        openWith.Add("dib""paint.exe");
        openWith.Add("rtf""wordpad.exe");
 
        // The Add method throws an exception if the new key is 
        // already in the hash table.
        try
        {
            openWith.Add("txt""winword.exe");
        }
        catch
        {
            Console.WriteLine("An element with Key = \"txt\" already exists.");
        }
 
        // The Item property is the default property, so you 
        // can omit its name when accessing elements. 
        Console.WriteLine("For key = \"rtf\", value = {0}.", openWith["rtf"]);
 
        // The default Item property can be used to change the value
        // associated with a key.
        openWith["rtf"= "winword.exe";
        Console.WriteLine("For key = \"rtf\", value = {0}.", openWith["rtf"]);
 
        // If a key does not exist, setting the default Item property
        // for that key adds a new key/value pair.
        openWith["doc"= "winword.exe";
 
        // ContainsKey can be used to test keys before inserting 
        // them.
        if (!openWith.ContainsKey("ht"))
        {
            openWith.Add("ht""hypertrm.exe");
            Console.WriteLine("Value added for key = \"ht\": {0}", openWith["ht"]);
        }
 
        // When you use foreach to enumerate hash table elements,
        // the elements are retrieved as KeyValuePair objects.
        Console.WriteLine();
        foreach (DictionaryEntry de in openWith)
        {
            Console.WriteLine("Key = {0}, Value = {1}", de.Key, de.Value);
        }
 
        // To get the values alone, use the Values property.
        ICollection valueColl = openWith.Values;
 
        // The elements of the ValueCollection are strongly typed
        // with the type that was specified for hash table values.
        Console.WriteLine();
        foreach (string s in valueColl)
        {
            Console.WriteLine("Value = {0}", s);
        }
 
        // To get the keys alone, use the Keys property.
        ICollection keyColl = openWith.Keys;
 
        // The elements of the KeyCollection are strongly typed
        // with the type that was specified for hash table keys.
        Console.WriteLine();
        foreach (string s in keyColl)
        {
            Console.WriteLine("Key = {0}", s);
        }
 
        // Use the Remove method to remove a key/value pair.
        Console.WriteLine("\nRemove(\"doc\")");
        openWith.Remove("doc");
 
        if (!openWith.ContainsKey("doc"))
        {
            Console.WriteLine("Key \"doc\" is not found.");
        }
 
        //
        //openWith.Add(0, "wordpad.exe11");
        openWith[0= "wordpad.exe11";
 
        //키 값은 null 이 될 수 없지만 값은 null 이 될 수 있습니다
        //openWith.Add(null, "wordpad.exe11");        //error : 'Key cannot be null.'
        //openWith.Add(0, null);
 
        object t1 = new object();
        object t2 = new object();
        openWith.Add(t1, "sdfsdf");
        openWith.Add(t2, "sdfsdf123");
        Console.WriteLine(openWith[t1]);
        Console.WriteLine(openWith[t2]);
 
        Console.WriteLine(openWith[0]);
 
 
        Console.WriteLine();
        foreach (DictionaryEntry de in openWith)
        {
            Console.WriteLine("Key = {0}, Value = {1}", de.Key, de.Value);
        }
 
 
    }
}
 
 
/*
An element with Key = "txt" already exists.
For key = "rtf", value = wordpad.exe.
For key = "rtf", value = winword.exe.
Value added for key = "ht": hypertrm.exe
Key = txt, Value = notepad.exe
Key = doc, Value = winword.exe
Key = ht, Value = hypertrm.exe
Key = bmp, Value = paint.exe
Key = dib, Value = paint.exe
Key = rtf, Value = winword.exe
Value = notepad.exe
Value = winword.exe
Value = hypertrm.exe
Value = paint.exe
Value = paint.exe
Value = winword.exe
Key = txt
Key = doc
Key = ht
Key = bmp
Key = dib
Key = rtf
Remove("doc")
Key "doc" is not found.
sdfsdf
sdfsdf123
wordpad.exe11
Key = System.Object, Value = sdfsdf123
Key = txt, Value = notepad.exe
Key = System.Object, Value = sdfsdf
Key = ht, Value = hypertrm.exe
Key = bmp, Value = paint.exe
Key = dib, Value = paint.exe
Key = rtf, Value = winword.exe
Key = 0, Value = wordpad.exe11
*/

cs



이름설명
System_CAPS_pubmethodHashtable()

비어 있는 새 인스턴스를 초기화는 Hashtable 기본 초기 용량을 사용 하 여 클래스, 로드 비율, 해시 코드 공급자 및 비교자입니다.

System_CAPS_pubmethodHashtable(IDictionary)

새 인스턴스를 초기화는 Hashtable 지정된 된 사전에서 새 요소를 복사 하 여 클래스 Hashtable 개체입니다. 새 Hashtable 개체는 복사 된 요소 수와 동일한 초기 용량을 갖고와 기본 로드 비율, 해시 코드 공급자 및 비교자를 사용 하 여 합니다.

System_CAPS_pubmethodHashtable(IDictionary, IEqualityComparer)

새 인스턴스를 초기화는 Hashtable 지정된 된 사전에서 새 요소를 복사 하 여 클래스 Hashtable 개체입니다. 새 Hashtable 개체는 복사 된 요소 수와 동일한 초기 용량을 갖고와 기본 로드 비율 및 지정 된 사용 하 여 IEqualityComparer 개체입니다.

System_CAPS_pubmethodHashtable(IDictionary, IHashCodeProvider, IComparer)

사용되지 않습니다. 새 인스턴스를 초기화는 Hashtable 지정된 된 사전에서 새 요소를 복사 하 여 클래스 Hashtable 개체입니다. 새 Hashtable 개체는 복사 된 요소 수와 동일한 초기 용량을 갖고와 기본 로드 비율과 지정 된 해시 코드 공급자 및 비교자를 사용 하 여 합니다. 이 API는 더 이상 사용되지 않습니다. 다른 방법에 대 한 참조 Hashtable합니다.

System_CAPS_pubmethodHashtable(IDictionary, Single)

새 인스턴스를 초기화는 Hashtable 지정된 된 사전에서 새 요소를 복사 하 여 클래스 Hashtable 개체입니다. 새 Hashtable 개체는 복사 된 요소 수와 동일한 초기 용량을 갖고 및 지정 된 로드 비율과 기본 해시 코드 공급자 및 비교자를 사용 하 여 합니다.

System_CAPS_pubmethodHashtable(IDictionary, Single, IEqualityComparer)

새 인스턴스를 초기화는 Hashtable 지정된 된 사전에서 새 요소를 복사 하 여 클래스 Hashtable 개체입니다. 새 Hashtable 개체는 복사 된 요소 수와 동일한 초기 용량을 갖고 및 지정 된 로드 비율을 사용 하 고 IEqualityComparer 개체입니다.

System_CAPS_pubmethodHashtable(IDictionary, Single, IHashCodeProvider, IComparer)

사용되지 않습니다. 새 인스턴스를 초기화는 Hashtable 지정된 된 사전에서 새 요소를 복사 하 여 클래스 Hashtable 개체입니다. 새 Hashtable 개체 초기 용량이 복사 된 요소 수와 동일 하 고 지정된 로드 비율, 해시 코드 공급자 및 비교자를 사용 합니다.

System_CAPS_pubmethodHashtable(IEqualityComparer)

비어 있는 새 인스턴스를 초기화는 Hashtable 기본 초기 용량을 사용 하 여 클래스 및 로드 비율과 지정 된 IEqualityComparer 개체입니다.

System_CAPS_pubmethodHashtable(IHashCodeProvider, IComparer)

사용되지 않습니다. 비어 있는 새 인스턴스를 초기화는 Hashtable 기본 초기 용량을 사용 하 여 클래스 및 로드 비율과 지정 된 해시 코드 공급자 및 비교자입니다.

System_CAPS_pubmethodHashtable(Int32)

비어 있는 새 인스턴스를 초기화는 Hashtable 지정된 된 초기 용량을 기본 로드 비율, 해시 코드 공급자 및 비교자를 사용 하 여 클래스입니다.

System_CAPS_pubmethodHashtable(Int32, IEqualityComparer)

비어 있는 새 인스턴스를 초기화는 Hashtable 지정된 된 초기 용량을 사용 하 여 클래스 및 IEqualityComparer, 및 기본 로드 비율입니다.

System_CAPS_pubmethodHashtable(Int32, IHashCodeProvider, IComparer)

사용되지 않습니다. 비어 있는 새 인스턴스를 초기화는 Hashtable 지정된 된 초기 용량, 해시 코드 공급자, 비교자 및 기본 로드 비율을 사용 하 여 클래스입니다.

System_CAPS_pubmethodHashtable(Int32, Single)

비어 있는 새 인스턴스를 초기화는 Hashtable 지정된 된 초기 용량을 사용 하 여 클래스 및 로드 비율과 기본 해시 코드 공급자 및 비교자입니다.

System_CAPS_pubmethodHashtable(Int32, Single, IEqualityComparer)

비어 있는 새 인스턴스를 초기화는 Hashtable 지정 된 초기 용량, 로드 비율을 사용 하 여 클래스 및 IEqualityComparer 개체입니다.

System_CAPS_pubmethodHashtable(Int32, Single, IHashCodeProvider, IComparer)

사용되지 않습니다. 비어 있는 새 인스턴스를 초기화는 Hashtable 지정된 된 초기 용량을 사용 하 여 클래스, 로드 비율, 해시 코드 공급자 및 비교자입니다.

System_CAPS_protmethodHashtable(SerializationInfo, StreamingContext)

비어 있는 새 인스턴스를 초기화는 Hashtable 클래스를 사용 하 여 지정 된 직렬화 가능 SerializationInfo및 StreamingContext 개체입니다.

이름설명
System_CAPS_protpropertycomparer

사용되지 않습니다. 가져오거나는 IComparer 를 사용 하는 Hashtable합니다.

System_CAPS_pubpropertyCount

Hashtable에 포함된 키/값 쌍의 수를 가져옵니다.

System_CAPS_protpropertyEqualityComparer

가져옵니다는 IEqualityComparer 를 사용 하는 Hashtable합니다.

System_CAPS_protpropertyhcp

사용되지 않습니다. 해시 코드를 분배할 수 있는 개체를 가져오거나 설정합니다.

System_CAPS_pubpropertyIsFixedSize

Hashtable의 크기가 고정되어 있는지를 나타내는 값을 가져옵니다.

System_CAPS_pubpropertyIsReadOnly

Hashtable가 읽기 전용인지 여부를 나타내는 값을 가져옵니다.

System_CAPS_pubpropertyIsSynchronized

Hashtable에 대한 액세스가 동기화되어 스레드로부터 안전하게 보호되는지를 나타내는 값을 가져옵니다.

System_CAPS_pubpropertyItem[Object]

지정된 키에 연결된 값을 가져오거나 설정합니다.

System_CAPS_pubpropertyKeys

가져옵니다는 ICollection 키를 포함 하는 Hashtable합니다.

System_CAPS_pubpropertySyncRoot

Hashtable에 대한 액세스를 동기화하는 데 사용할 수 있는 개체를 가져옵니다.

System_CAPS_pubpropertyValues

ICollection의 값이 들어 있는 Hashtable을 가져옵니다.

이름설명
System_CAPS_pubmethodAdd(Object, Object)

지정한 키와 값을 가지는 요소를 Hashtable에 추가합니다.

System_CAPS_pubmethodClear()

Hashtable에서 요소를 모두 제거합니다.

System_CAPS_pubmethodClone()

Hashtable의 부분 복사본을 만듭니다.

System_CAPS_pubmethodContains(Object)

Hashtable에 특정 키가 들어 있는지 여부를 확인합니다.

System_CAPS_pubmethodContainsKey(Object)

Hashtable에 특정 키가 들어 있는지 여부를 확인합니다.

System_CAPS_pubmethodContainsValue(Object)

Hashtable에 특정 값이 들어 있는지 여부를 확인합니다.

System_CAPS_pubmethodCopyTo(Array, Int32)

복사본은 Hashtable 요소를 1 차원 Array 인스턴스의 지정한 인덱스에 있습니다.

System_CAPS_pubmethodEquals(Object)

지정한 개체와 현재 개체가 같은지 여부를 확인합니다.(Object에서 상속됨)

System_CAPS_protmethodFinalize()

가비지 컬렉션이 회수하기 전에 개체가 리소스를 해제하고 다른 정리 작업을 수행할 수 있게 합니다.(Object에서 상속됨)

System_CAPS_pubmethodGetEnumerator()

반환 된 IDictionaryEnumerator 을 반복 하는 Hashtable합니다.

System_CAPS_protmethodGetHash(Object)

지정한 키의 해시 코드를 반환합니다.

System_CAPS_pubmethodGetHashCode()

기본 해시 함수로 작동합니다.(Object에서 상속됨)

System_CAPS_pubmethodGetObjectData(SerializationInfo, StreamingContext)

구현 하는 ISerializable 인터페이스를 serialize 하는 데 필요한 데이터를 반환 된 Hashtable합니다.

System_CAPS_pubmethodGetType()

현재 인스턴스의 Type을 가져옵니다.(Object에서 상속됨)

System_CAPS_protmethodKeyEquals(Object, Object)

특정 비교 Object 에 특정 키로는 Hashtable합니다.

System_CAPS_protmethodMemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.(Object에서 상속됨)

System_CAPS_pubmethodOnDeserialization(Object)

ISerializable 인터페이스를 구현하고, deserialization이 완료되면 deserialization 이벤트를 발생시킵니다.

System_CAPS_pubmethodRemove(Object)

Hashtable에서 지정한 키를 가지는 요소를 제거합니다.

System_CAPS_pubmethodSystem_CAPS_staticSynchronized(Hashtable)

동기화 (스레드로부터 안전한 지) 래퍼를 반환 된 Hashtable합니다.

System_CAPS_pubmethodToString()

현재 개체를 나타내는 문자열을 반환합니다.(Object에서 상속됨)

이름설명
System_CAPS_pubinterfaceSystem_CAPS_privmethodIEnumerable.GetEnumerator()

컬렉션을 반복하는 열거자를 반환합니다.

이름설명
System_CAPS_pubmethodAsParallel()

오버로드되었습니다. 쿼리를 병렬화할 수 있도록 합니다.(ParallelEnumerable에서 정의됨)

System_CAPS_pubmethodAsQueryable()

오버로드되었습니다. 변환 된 IEnumerable 에 IQueryable합니다.(Queryable에서 정의됨)

System_CAPS_pubmethodCast<TResult>()

요소에 캐스트는 IEnumerable 지정 된 형식입니다.(Enumerable에서 정의됨)

System_CAPS_pubmethodOfType<TResult>()

요소를 필터링 한 IEnumerable 지정된 된 형식에 기반 합니다.(Enumerable에서 정의됨)


ref : https://msdn.microsoft.com/ko-kr/library/system.collections.hashtable(v=vs.110).aspx




반응형

+ Recent posts