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


// Make a Point by setting each property manually



Download 21,46 Mb.
Pdf ko'rish
bet861/1830
Sana28.09.2021
Hajmi21,46 Mb.
#188411
1   ...   857   858   859   860   861   862   863   864   ...   1830
Bog'liq
[book] [en] Pro C# 2008 and the NET 3.5 Platform Fourth Edition

// Make a Point by setting each property manually...

Point firstPoint = new Point();

C H A P T E R   1 3  

C #   2 0 0 8   L A N G U A G E   F E AT U R E S



436

8849CH13.qxd  10/2/07  12:42 PM  Page 436




firstPoint.X = 10;

firstPoint.Y = 10;



// ...or make a Point via a custom constructor...

Point anotherPoint = new Point(20, 20);



// ...or make some Point types using the new object init syntax.

var yetAnotherPoint = new Point { X = 30, Y = 30 };

Point finalPoint = new Point { X = 30, Y = 30 };

Console.ReadLine();

}

The final two Point types (one of which is implicitly typed, just for the purpose of illustration)



are not making use of a custom type constructor (as one might do traditionally), but are rather set-

ting values to the public X and Y properties. Behind the scenes, the type’s default constructor is

invoked, followed by setting the values to the specified properties. To this end, yetAnotherPoint and

finalPoint are just shorthand notations for the syntax used to create the firstPoint variable (going

property by property).

Now recall that this same syntax can be used to set public fields of a type, which Point cur-

rently does not support. However, for the sake of argument, assume that the xPos and yPos member

variables have been declared publicly. We could now set values to these fields as follows:

var p = new Point {xPos = 2, yPos = 3};

Given that Point now has four public members, the following syntax is also legal. However, try

to figure out the actual final values of xPos and yPos:

var p = new Point {xPos = 2, yPos = 3, X = 900};

As you might guess, xPos is set to 900, while yPos is the value 3. From this, you can correctly

infer that object initialization is performed in a left-to-right manner. To clarify, the previous initial-

ization of p using standard object constructor syntax would appear as follows:

Point p = new Point();

p.xPos = 2;

p.yPos = 3;

p.X = 900;


Download 21,46 Mb.

Do'stlaringiz bilan baham:
1   ...   857   858   859   860   861   862   863   864   ...   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