C# 0 The Complete Reference



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

SortedList

. It reworks the employee 

database example one more time. In this version, the database is stored in a 

SortedList

.

// Demonstrate a SortedList.



using System;

using System.Collections.Generic;

class GenSLDemo {

  static void Main() {

    // Create a sorted SortedList for

    // employee names and salary.

    SortedList sl =

      new SortedList();

public int IndexOfValue(TV 

v

)

Returns the index of the first occurrence of the 



value specified by 

v.

 Returns –1 if the value is not in 

the list.

public bool Remove(TK 



k

)

Removes the key/value pair associated with 



k

 from 


the list. Returns true if successful. Returns false if 

k

is not in the list.

public void RemoveAt(int 

idx

)

Removes the key/value pair at the index specified 



by

idx.

public void TrimExcess( )

Removes the excess capacity of the invoking list.

T

ABLE



 24-18 

Several Commonly Used Methods Defi ned by 

SortedList 

(continued)

Method


Description

www.freepdf-books.com




794

 

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

    // Add elements to the collection.

    sl.Add("Butler, John", 73000);

    sl.Add("Swartz, Sarah", 59000);

    sl.Add("Pyke, Thomas", 45000);

    sl.Add("Frank, Ed", 99000);

    // Get a collection of the keys.

    ICollection c = sl.Keys;

    // Use the keys to obtain the values.

    foreach(string str in c)

      Console.WriteLine("{0}, Salary: {1:C}", str, sl[str]);

    Console.WriteLine();

  }

}

The output is shown here:



Butler, John, Salary: $73,000.00

Frank, Ed, Salary: $99,000.00

Pyke, Thomas, Salary: $45,000.00

Swartz, Sarah, Salary: $59,000.00

As the output shows, the list is sorted based on employee name, which is the key.


Download 4,07 Mb.

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