This print for content only-size & color not accurate 7" X 9-1/4" / casebound / malloy


// The iteration of the Car can be ordered



Download 21,46 Mb.
Pdf ko'rish
bet598/1830
Sana28.09.2021
Hajmi21,46 Mb.
#188411
1   ...   594   595   596   597   598   599   600   601   ...   1830
Bog'liq
[book] [en] Pro C# 2008 and the NET 3.5 Platform Fourth Edition

// The iteration of the Car can be ordered

// based on the CarID.

public class Car : IComparable

{

...


// IComparable implementation.

int IComparable.CompareTo(object obj)

{

Car temp = (Car)obj;



if(this.carID > temp.carID)

return 1;

if(this.carID < temp.carID)

return -1;

else

return 0;



}

}

As you can see, the logic behind CompareTo() is to test the incoming type against the current



instance based on a specific point of data. The return value of CompareTo() is used to discover

whether this type is less than, greater than, or equal to the object it is being compared with (see

Table 9-1).

Table 9-1. CompareTo() Return Values

CompareTo() Return Value

Meaning in Life

Any number less than zero

This instance comes before the specified object in the sort

order.


Zero

This instance is equal to the specified object.

Any number greater than zero

This instance comes after the specified object in the sort order.

We can streamline the previous implementation of CompareTo() given the fact that the C# int

data type (which is just a shorthand notation for the CLR System.Int32) implements IComparable;

you could implement the Car’s CompareTo() as follows:

int IComparable.CompareTo(object obj)

{

Car temp = (Car)obj;



return this.carID.CompareTo(temp.carID);

}

In either case, so that your Car type understands how to compare itself to like objects, you can



write the following user code:


Download 21,46 Mb.

Do'stlaringiz bilan baham:
1   ...   594   595   596   597   598   599   600   601   ...   1830




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