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


// Assigning two intrinsic value types results in



Download 21,46 Mb.
Pdf ko'rish
bet289/1830
Sana28.09.2021
Hajmi21,46 Mb.
#188411
1   ...   285   286   287   288   289   290   291   292   ...   1830
Bog'liq
[book] [en] Pro C# 2008 and the NET 3.5 Platform Fourth Edition

// Assigning two intrinsic value types results in

// two independent variables on the stack.

static void ValueTypeAssignment()

{

Console.WriteLine("Assigning value types\n");



Point p1 = new Point(10, 10);

Point p2 = p1;



// Print both points.

p1.Display();

p2.Display();

// Change p1.X and print again. p2.X is not changed.

p1.X = 100;

Console.WriteLine("\n=> Changed p1.X\n");

p1.Display();

p2.Display();

}

Here you have created a variable of type Point (named p1) that is then assigned to another



Point (p2). Because Point is a value type, you have two copies of the MyPoint type on the stack, each

of which can be independently manipulated. Therefore, when you change the value of p1.X, the

value of p2.X is unaffected. Figure 4-10 shows the output once this method is called from Main().

Figure 4-10.

Assignment of value types results in a verbatim copy of each field.

In stark contrast to value types, when you apply the assignment operator to reference types

(meaning all class instances), you are redirecting what the reference variable points to in memory.

To illustrate, create a new class type named PointRef that has the exact same members as the Point

structures, beyond renaming the constructor to match the class name:


Download 21,46 Mb.

Do'stlaringiz bilan baham:
1   ...   285   286   287   288   289   290   291   292   ...   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