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


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



Download 21,46 Mb.
Pdf ko'rish
bet593/1830
Sana28.09.2021
Hajmi21,46 Mb.
#188411
1   ...   589   590   591   592   593   594   595   596   ...   1830
Bog'liq
[book] [en] Pro C# 2008 and the NET 3.5 Platform Fourth Edition

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



297

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




public object Clone()

{ return this.MemberwiseClone(); }

public override string ToString()

{

return string.Format("X = {0}; Y = {1}; Name = {2};\nID = {3}\n",



x, y, desc.petName, desc.pointID);

}

}



Notice that you did not yet update your Clone() method. Therefore, when the object user asks

for a clone using the current implementation, a shallow (member-by-member) copy is achieved. To

illustrate, assume you have updated Main() as follows:

static void Main(string[] args)

{

Console.WriteLine("***** Fun with Object Cloning *****\n");



Console.WriteLine("Cloned p3 and stored new Point in p4");

Point p3 = new Point(100, 100, "Jane");

Point p4 = (Point)p3.Clone();

Console.WriteLine("Before modification:");

Console.WriteLine("p3: {0}", p3);

Console.WriteLine("p4: {0}", p4);

p4.desc.petName = "My new Point";

p4.x = 9;

Console.WriteLine("\nChanged p4.desc.petName and p4.x");

Console.WriteLine("After modification:");

Console.WriteLine("p3: {0}", p3);

Console.WriteLine("p4: {0}", p4);

Console.ReadLine();

}

Figure 9-11 shows the output. Notice that while the value types have indeed been changed, the



internal reference types maintain the same values, as they are “pointing” to the same objects in

memory.



Download 21,46 Mb.

Do'stlaringiz bilan baham:
1   ...   589   590   591   592   593   594   595   596   ...   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