C# 0 The Complete Reference


The SortedDictionary Class



Download 4,07 Mb.
Pdf ko'rish
bet980/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   976   977   978   979   980   981   982   983   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

The SortedDictionary Class

The


SortedDictionary

 class stores key/value pairs and is similar to 



Dictionary

TV>

 except that it is sorted by key. 



SortedDictionary

 implements 



IDictionary

,

IDictionary

,

ICollection

,

 ICollection>

,

IEnumerable

,

and



IEnumerable>

.

SortedDictionary

 provides the 

following constructors:

public SortedDictionary( )

public SortedDictionary(IDictionary 



dict

)

public SortedDictionary(IComparer 



comp

)

public SortedDictionary(IDictionary 



dict

, IComparer 



comp

)

The first constructor creates an empty dictionary. The second creates a dictionary that 



contains the same elements as those in 

dict.

 The third lets you specify the 



IComparer

 that 


the dictionary will use for sorting, and the fourth lets you initialize the dictionary and 

specify the 



IComparer

.

SortedDictionary

 defines several methods. A sampling is shown in Table 24-17.

www.freepdf-books.com




790

 

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

In addition to the properties defined by the interfaces that it implements, 



SortedDictionary

 defines the following properties:

Property

Description

public IComparer Comparer { get; }

Obtains the comparer for the invoking 

dictionar y.

public


    Sor tedDictionar y.KeyCollection

         Keys { get; }

Obtains a collection of the keys. 

public


    Sor tedDictionar y.ValueCollection

          Values { get; }

Obtains a collection of the values. 

Notice that the keys and values contained within the collection are available as separate lists 

through the 

Keys

 and 


Values

 properties. The types

SortedDictionary.KeyCollection

SortedDictionary.ValueCollection

are collections that implement both the generic and non-generic forms of 

ICollection

 and 


IEnumerable

.

SortedDictionary

 defines the following indexer (which is specified by 

IDictionary

):

public TV this[TK 



key

] { get; set; }

You can use this indexer to get or set the value of an element. You can also use it to add a 

new element to the collection. Notice that the “index” is not actually an index, but rather the 

key of the item.

Method


Description

public void Add(TK 



k

, TV 


v

)

Adds the key/value pair specified by 



k

 and 


v

 to the dictionar y. If 



k

 is already in the 

dictionar y, then its value is unchanged and 

an

ArgumentException



 is thrown.

public bool ContainsKey(TK 



k

)

Returns true if 



k

 is a key in the invoking 

dictionar y. Returns false other wise.

public bool ContainsValue(TV 



v

)

Returns true if 



v

 is a value in the invoking 

dictionar y. Returns false other wise.

public Sor tedDictionar y.Enumerator

     GetEnumerator( )

Returns an enumerator for the invoking 

dictionar y. 

public bool Remove(TK 



k

)

Removes 



k

 from the dictionar y. Returns true 

if successful. Returns false if

k

 was not in 

the dictionar y.

T

ABLE



 24-17 

A Sampling of Methods Defi ned by 

SortedDictionary

www.freepdf-books.com




Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   976   977   978   979   980   981   982   983   ...   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