C# 0 The Complete Reference



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

Dictionary 

defines these properties:

Property

Description

public IEqualityComparer

    Comparer { get; }

Obtains the comparer for the invoking dictionar y.

public Dictionar y.KeyCollection

    Keys { get; }

Obtains a collection of the keys.

public Dictionar 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 



Dictionary.KeyCollection

and


Dictionary.ValueCollection 

are collections that implement both the generic 

and non-generic forms of 

ICollection

 and 


IEnumerable

.

The following indexer, defined by 



IDictionary

, is implemented by 



Dictionary

 as shown here:

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.

When enumerating the collection, 



Dictionary

 returns key/value pairs in the 

form of a 

KeyValuePair

 structure. Recall that this structure defines the following 

two fields:

public TK Key;

public TV Value;

These fields hold the key or value associated with an entry. Most of the time you won’t need 

to use 

KeyValuePair

 directly because 



Dictionary

 allows you to work 

the keys and values individually. However, when enumerating a 

Dictionary

, such 


as in a 

foreach

 loop, the objects being enumerated are 



KeyValuePair

s.

In a 



Dictionary

, all keys must be unique, and a key must not change while it 

is in use as a key. Values need not be unique. The objects in a 

Dictionary

 are not 

stored in sorted order.

Here is an example that demonstrates 



Dictionary

:

// Demonstrate the generic Dictionary class.



using System;

using System.Collections.Generic;

class GenDictionaryDemo {

www.freepdf-books.com




Download 4,07 Mb.

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