C# 0 The Complete Reference


PART II C h a p t e r   2 4



Download 4,07 Mb.
Pdf ko'rish
bet996/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   992   993   994   995   996   997   998   999   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt


PART II

C h a p t e r   2 4 :  

C o l l e c t i o n s ,   E n u m e r a t o r s ,   a n d   I t e r a t o r s    

803


    return name.CompareTo(b.name);

  }


}

class IComparableDemo {

  static void Main() {

    ArrayList inv = new ArrayList();

    // Add elements to the list.

    inv.Add(new Inventory("Pliers", 5.95, 3));

    inv.Add(new Inventory("Wrenches", 8.29, 2));

    inv.Add(new Inventory("Hammers", 3.50, 4));

    inv.Add(new Inventory("Drills", 19.88, 8));

    Console.WriteLine("Inventory list before sorting:");

    foreach(Inventory i in inv) {

      Console.WriteLine("   " + i);

    }

    Console.WriteLine();



    // Sort the list.

    inv.Sort();

    Console.WriteLine("Inventory list after sorting:");

    foreach(Inventory i in inv) {

      Console.WriteLine("   " + i);

    }


  }

}

Here is the output. Notice that after the call to 



Sort( )

, the inventory is sorted by name.

Inventory list before sorting:

   Pliers    Cost:  $5.95  On hand: 3

   Wrenches  Cost:  $8.29  On hand: 2

   Hammers   Cost:  $3.50  On hand: 4

   Drills    Cost: $19.88  On hand: 8

Inventory list after sorting:

   Drills    Cost: $19.88  On hand: 8

   Hammers   Cost:  $3.50  On hand: 4

   Pliers    Cost:  $5.95  On hand: 3

   Wrenches  Cost:  $8.29  On hand: 2




Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   992   993   994   995   996   997   998   999   ...   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