C# 0 The Complete Reference


ThreeD ’s operator+( )



Download 4,07 Mb.
Pdf ko'rish
bet322/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   318   319   320   321   322   323   324   325   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

ThreeD

’s

operator+( )

 is automatically invoked, and 

b

 will contain the coordinate 11, 12, 13.

One last point: Although you cannot overload the 

[ ]

 array indexing operator using an 



operator

 method, you can create indexers, which are described in the next chapter.



Another Example of Operator Overloading

Throughout this chapter we have been using the 



ThreeD

 class to demonstrate operator 

overloading, and in this regard it has served us well. Before concluding this chapter, 

however, it is useful to work through another example. Although the general principles 

of operator overloading are the same no matter what class is used, the following example 

helps show the power of operator overloading—especially where type extensibility is 

concerned.

This example develops a four-bit integer type and defines several operations for it. As 

you might know, in the early days of computing, the four-bit quantity was common because 

it represented half a byte. It is also large enough to hold one hexadecimal digit. Since four 

bits are half a byte, a four-bit quantity is sometimes referred to as a 

nybble.

 In the days of 

front-panel machines in which programmers entered code one nybble at a time, thinking in 

terms of nybbles was an everyday affair! Although not as common now, a four-bit type still 

makes an interesting addition to the other C# integers. Traditionally, a nybble is an unsigned 

value.


The following example uses the 


Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   318   319   320   321   322   323   324   325   ...   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