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


// Two references to same object!



Download 21,46 Mb.
Pdf ko'rish
bet589/1830
Sana28.09.2021
Hajmi21,46 Mb.
#188411
1   ...   585   586   587   588   589   590   591   592   ...   1830
Bog'liq
[book] [en] Pro C# 2008 and the NET 3.5 Platform Fourth Edition

// Two references to same object!

Point p1 = new Point(50, 50);

Point p2 = p1;

p2.x = 0;

Console.WriteLine(p1);

Console.WriteLine(p2);

Console.ReadLine();

}

When you wish to equip your custom types to support the ability to return an identical copy of



itself to the caller, you may implement the standard ICloneable interface. As shown at the start of

this chapter, this type defines a single method named Clone():

C H A P T E R   9  

W O R K I N G   W I T H   I N T E R FA C E S



295

8849CH09.qxd  10/1/07  10:41 AM  Page 295




public interface ICloneable

{

object Clone();



}



Note

The usefulness of the 

ICloneable

interface is currently under debate within the .NET community. The

problem has to do with the fact that the official specification does not explicitly say that objects implementing this

interface must return a deep copy of the object (i.e., internal reference types of an object result in brand-new

objects with identical state). Thus, it is technically possible that objects implementing 

ICloneable

actually return

shallow copy of the interface (i.e., internal references point to the same object on the heap), which clearly gener-

ates a good deal of confusion. In our example, I am assuming we are implementing 

Clone()


to return a full, deep

copy of the object.

Obviously, the implementation of the Clone() method varies between objects. However, the

basic functionality tends to be the same: copy the values of your member variables into a new

object instance of the same type, and return it to the user. To illustrate, ponder the following update

to the Point class:




Download 21,46 Mb.

Do'stlaringiz bilan baham:
1   ...   585   586   587   588   589   590   591   592   ...   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