C# 0 The Complete Reference


IComparable . The IEquatable Interface



Download 4,07 Mb.
Pdf ko'rish
bet815/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   811   812   813   814   815   816   817   818   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

IComparable

.

The IEquatable Interface



IEquatable

is implemented by those classes that need to define how two objects should 

be compared for equality. It defines only one method, 

Equals( )

, which is shown here:

bool Equals(T 

obj

)

The method returns 



true

 if 


obj

 is equal to the invoking object and 



false

 otherwise.



IEquatable

 is implemented by several classes and structures in the .NET Framework, 

including the numeric structures, 

Char

,

Int32

,

Boolean

, and 


String

.

The IConvertible Interface

The

 IConvertible

 interface is implemented by all of the value-type structures



string

, and 


DateTime

. It specifies various type conversions. Normally, classes that you create will not 

need to implement this interface.

The ICloneable Interface

By implementing the 



ICloneable

 interface, you enable a copy of an object to be made. 



ICloneable

 defines only one method, 



Clone( )

, which is shown here:

object Clone( )

This method makes a copy of the invoking object. How you implement 



Clone( )

determines how the copy is made. In general, there are two types of copies: deep and 

shallow. When a deep copy is made, the copy and original are completely independent. 

Thus, if the original object contained a reference to another object 



O,

 then a copy of 



O

 will 


also be made. In a shallow copy, members are copied, but objects referred to by members 

are not. If an object refers to some other object 



O,

 then after a shallow copy, both the copy 

and the original will refer to the same 

O,

 and any changes to 



O

 affect both the copy and the 

original. Usually, you will implement 

Clone( )

 so that it performs a deep copy. Shallow 

copies can be made by using 

MemberwiseClone( )

, which is defined by 



Object

.

Here is an example that illustrates 



ICloneable

. It creates a class called 



Test

 that contains 

a reference to an object of a class called 

X

.

Test

 uses 

Clone( ) 

to create a deep copy.

// Demonstrate ICloneable.

using System;

class X {

www.freepdf-books.com




Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   811   812   813   814   815   816   817   818   ...   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