C# 0 The Complete Reference


PART I C h a p t e r   9



Download 4,07 Mb.
Pdf ko'rish
bet297/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   293   294   295   296   297   298   299   300   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt


PART I

C h a p t e r   9 :  

O p e r a t o r   O v e r l o a d i n g  

217


PART IPART I

Here, a new object is created that contains the negated fields of the operand. This object 

is then returned. Notice that the operand is unchanged. Again, this is in keeping with the 

usual meaning of the unary minus. For example, in an expression such as this,

a = -b

a

 receives the negation of 



b

, but 


b

 is not changed.

In C#, overloading 

++

 and 


– –

 is quite easy; simply return the incremented or decremented 

value, but don’t change the invoking object. C# will automatically handle that for you, 

taking into account the difference between the prefix and postfix forms. For example, here 

is an 

operator++( )

 method for the 



ThreeD

 class:


// Overload unary ++.

public static ThreeD operator ++(ThreeD op)

{

  ThreeD result = new ThreeD();



  // Return the incremented result.

  result.x = op.x + 1;

  result.y = op.y + 1;

  result.z = op.z + 1;

  return result;

}

Here is an expanded version of the previous example program that demonstrates the 



unary


Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   293   294   295   296   297   298   299   300   ...   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