C# 0 The Complete Reference



Download 4,07 Mb.
Pdf ko'rish
bet948/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   944   945   946   947   948   949   950   951   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

EqualityComparer

 and 


KeyComparer

. Two other properties called 



hcp

 and 


comparer

are flagged as obsolete.



Hashtable

 stores key/value pairs in the form of a 



DictionaryEntry

 structure, but most 

of the time, you won’t be aware of it directly because the properties and methods work with 

keys and values individually. For example, when you add an element to a 



Hashtable

, you 


call

Add( )

, which takes two arguments: the key and the value.

It is important to note that 

Hashtable

 does not guarantee the order of its elements. This 

is because the process of hashing does not usually lend itself to the creation of sorted tables.

Here is an example that demonstrates 



Hashtable

:

// Demonstrate Hashtable.



using System;

using System.Collections;

class HashtableDemo {

  static void Main() {

    // Create a hash table.

    Hashtable ht = new Hashtable();

    // Add elements to the table.

    ht.Add("house", "Dwelling");

    ht.Add("car", "Means of transport");

    ht.Add("book", "Collection of printed words");

    ht.Add("apple", "Edible fruit");

    // Can also add by using the indexer.

    ht["tractor"] = "Farm implement";

    // Get a collection of the keys.

    ICollection c = ht.Keys;

    // Use the keys to obtain the values.

    foreach(string str in c)

      Console.WriteLine(str + ": " + ht[str]);

  }

}

Method



Description

public vir tual bool ContainsKey(object 



k

)

Returns true if 



k

 is a key in the invoking 

Hashtable

.

Returns false other wise.



public vir tual bool ContainsValue(object 

v

)

Returns true if 



v

 is a value in the invoking 

Hashtable

.

Returns false other wise.



public vir tual IDictionar yEnumerator

    GetEnumerator( )

Returns an 

IDictionaryEnumerator

 for the invoking 

Hashtable

.

public static Hashtable



    Synchronized(Hashtable 

ht

)

Returns a synchronized version of the 



Hashtable

passed in 



ht.

T

ABLE



 24-5 

Several Commonly Used Methods Defi ned by 

Hashtable

www.freepdf-books.com




764

 

P a r t   I I :  



E x p l o r i n g   t h e   C #   L i b r a r y

The output from this program is shown here:

book: Collection of printed words

tractor: Farm implement

apple: Edible fruit

house: Dwelling

car: Means of transport

As the output shows, the key/value pairs are not stored in sorted order. Notice how the 

contents of the hash table 


Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   944   945   946   947   948   949   950   951   ...   1096




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish