C# 0 The Complete Reference


ob2  is a clone of  ob1



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

ob2

 is a clone of 



ob1

, but 


ob1

 and 


ob2

 are completely separate objects. 

Changing one does not affect the other. This is accomplished by constructing a new 

Test

object, which allocates a new 



X

 object for the copy. The new 



X

 instance is given the same 

value as the 

X

 object in the original.

To implement a shallow copy, simply have 

Clone( )

 call 


MemberwiseClone( )

 defined 

by

Object

. For example, try changing 



Clone( )

 in the preceding program as shown here:

// Make a shallow copy of the invoking object.

public object Clone() {

  Test temp = (Test) MemberwiseClone();

  return temp;

}

After making this change, the output of the program will look like this:



ob1 values are o.a: 10, b: 20

Make ob2 a clone of ob1.

ob2 values are o.a: 10, b: 20

Changing ob1.o.a to 99 and ob1.b to 88.

ob1 values are o.a: 99, b: 88

ob2 values are o.a: 99, b: 20

Notice that 


Download 4,07 Mb.

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