C# 0 The Complete Reference


PART I C h a p t e r   9



Download 4,07 Mb.
Pdf ko'rish
bet320/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   316   317   318   319   320   321   322   323   ...   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  

239


PART IPART I

if you remove the cast, the program will not compile.

There are a few restrictions to conversion operators:

•  Either the target type or the source type of the conversion must be the class in which 

the conversion is declared. You cannot, for example, redefine the conversion from 

double

 to 


int

.

•  You cannot define a conversion to or from 



object

.

•  You cannot define both an implicit and an explicit conversion for the same source 



and target types.

•  You cannot define a conversion from a base class to a derived class. (See Chapter 11 

for a discussion of base and derived classes.)

•  You cannot define a conversion from or to an interface. (See Chapter 12 for a 

discussion of interfaces.)

In addition to these rules, there are suggestions that you should normally follow when 

choosing between implicit and explicit conversion operators. Although convenient, implicit 

conversions should be used only in situations in which the conversion is inherently error-

free. To ensure this, implicit conversions should be created only when these two conditions 

are met: First, that no loss of information, such as truncation, overflow, or loss of sign, 

occurs. Second, that the conversion does not cause an exception. If the conversion cannot 

meet these two requirements, then you should use an explicit conversion.




Download 4,07 Mb.

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