C# 0 The Complete Reference



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

The SortedList Class

The


SortedList

 class stores a sorted list of key/value pairs. It is the generic 

equivalent of the non-generic 

SortedList

 class. 


SortedList

 implements 



IDictionary

,

IDictionary, ICollection

,

ICollection< KeyValuePair>

,

IEnumerable

, and 

IEnumerable< KeyValuePair>

. The size of a 



SortedList

TV>

 is dynamic and will automatically grow as needed. 



SortedList

 is similar to 



SortedDictionary

 but has different performance characteristics. For example, a 



SortedList

 uses less memory, but a 



SortedDictionary

 is faster when 

inserting out-of-order elements.

SortedList

 provides many constructors. Here is a sampling:

public SortedList( )

public SortedList(IDictionary 



dict

)

public SortedList(int 



capacity

)

public SortedList(IComparer 



comp

)

The first constructor creates an empty list with a default capacity. The second creates a list 



that contains the same elements as those in 

dict.

 The third lets you specify an initial capacity. 

If you know in advance that you will need a list of a certain size, then specifying that capacity 

will prevent the resizing of the list at runtime, which is a costly process. The fourth form lets 

you specify a comparison method that will be used to compare the objects contained in the list.

The capacity of a 



SortedList TV>

 list grows automatically as needed when elements 

are added to a list. When the current capacity is exceeded, the capacity is increased. The 

advantage of specifying a capacity is that you can prevent or minimize the overhead 

associated with resizing the collection. Of course, it makes sense to specify an initial 

capacity only if you have some idea of how many elements will be stored.

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

SortedList

TV>

 also defines several methods of its own. A sampling is shown in Table 24-18. Notice 

that the enumerator returned by 

GetEnumerator( )

 enumerates the key/value pairs stored 

in the list as objects of type 

KeyValuePair

.

Method



Description

public void Add(TK 



k

, TV 


v

)

Adds the key/value pair specified by 



k

 and 


v

 to 


the list. If 

k

 is already in the list, 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 list. Returns 

false other wise.

public bool ContainsValue(TV 



v

)

Returns true if 



v

 is a value in the invoking list. 

Returns false other wise.

public IEnumerator>

    GetEnumerator( )

Returns an enumerator for the invoking list.

public int IndexOfKey(TK 

k

)

Returns the index of the key specified by 



k.

 Returns 

–1 if the key is not in the list.

T

ABLE



 24-18 

Several Commonly Used Methods Defi ned by 

SortedList

www.freepdf-books.com




Download 4,07 Mb.

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