C# 0 The Complete Reference


+  is applied to two  ThreeD



Download 4,07 Mb.
Pdf ko'rish
bet302/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   298   299   300   301   302   303   304   305   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

+

 is applied to two 



ThreeD

 objects, their coordinates are 

added together. When the 

+

 is applied to a 



ThreeD

 object and an integer, the coordinates 

are increased by the integer value.

While the overloading of 



+

 just shown certainly adds a useful capability to the 



ThreeD

class, it does not quite finish the job. Here is why. The 



operator+(ThreeD, int)

 method 


allows statements like this:

ob1 = ob2 + 10;

It does not, unfortunately, allow ones like this:

ob1 = 10 + ob2;

The reason is that the integer argument is the second argument, which is the right-hand 

operand, but the preceding statement puts the integer argument on the left. To allow both 

forms of statements, you will need to overload the 

+

 yet another time. This version must 

have its first parameter as type 

int

 and its second parameter as type 



ThreeD

. One version of 

the

operator+( )

 method handles 



ThreeD

 + integer, and the other handles integer + 



ThreeD

.

Overloading the 



+

 (or any other binary operator) this way allows a built-in type to occur on 

the left or right side of the operator. Here is a version 

ThreeD

 that overloads the 



+

 operator 

as just described:

// Overload the + for ThreeD + ThreeD, ThreeD + int, and int + ThreeD.

using System;

// A three-dimensional coordinate class.

class ThreeD {

  int x, y, z; // 3-D coordinates

www.freepdf-books.com



Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   298   299   300   301   302   303   304   305   ...   1096




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