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


// Point p3 = Point.operator+ (p1, p2)



Download 21,46 Mb.
Pdf ko'rish
bet772/1830
Sana28.09.2021
Hajmi21,46 Mb.
#188411
1   ...   768   769   770   771   772   773   774   775   ...   1830
Bog'liq
[book] [en] Pro C# 2008 and the NET 3.5 Platform Fourth Edition

// Point p3 = Point.operator+ (p1, p2)

Point p3 = p1 + p2;

Likewise, p1 – p2 maps to the following:

// Point p4 = Point.operator- (p1, p2)

Point p4 = p1 - p2;

With this update, our program now compiles, and we find we are able to add and subtract

Point objects (see Figure 12-2).



Figure 12-2.

Redefining and for the Point type

Strictly speaking, when you are overloading a binary operator, you are not required to pass in

two parameters of the same type. If it makes sense to do so, one of the arguments can differ. For

example, here is an overloaded operator +, which allows the caller to obtain a new Point that is

based on a numerical adjustment:

public struct Point

{

...


public static Point operator +(Point p1, int change)

{

return new Point(p1.x + change, p1.y + change);



}

public static Point operator +(int change, Point p1)

{

return new Point(p1.x + change, p1.y + change);



}

}

We would now be able to use these new versions of operator + as follows:




Download 21,46 Mb.

Do'stlaringiz bilan baham:
1   ...   768   769   770   771   772   773   774   775   ...   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