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


Understanding Operator Overloading



Download 21,46 Mb.
Pdf ko'rish
bet767/1830
Sana28.09.2021
Hajmi21,46 Mb.
#188411
1   ...   763   764   765   766   767   768   769   770   ...   1830
Bog'liq
[book] [en] Pro C# 2008 and the NET 3.5 Platform Fourth Edition

Understanding Operator Overloading

C#, like any programming language, has a canned set of tokens that are used to perform basic oper-

ations on intrinsic types. For example, you know that the + operator can be applied to two integers

in order to yield a larger integer:



// The + operator with ints.

int a = 100;

int b = 240;

int c = a + b;

// c is now 340

Again, this is no major newsflash, but have you ever stopped and noticed how the same + oper-

ator can be applied to most intrinsic C# data types? For example, consider this code:

// + operator with strings.

string s1 = "Hello";

string s2 = " world!";

string s3 = s1 + s2;

// s3 is now "Hello world!"

C H A P T E R   1 2  



I N D E X E R S, O P E R ATO R S, A N D   P O I N T E R S



388

8849CH12.qxd  9/26/07  11:31 AM  Page 388




In essence, the + operator functions in unique ways based on the supplied data types (strings

or integers in this case). When the + operator is applied to numerical types, the result is the summa-

tion of the operands. However, when the + operator is applied to string types, the result is string

concatenation.

The C# language provides the capability for you to build custom classes and structures that

also respond uniquely to the same set of basic tokens (such as the + operator). Be aware that you

cannot overload each and every intrinsic C# operator. Table 12-1 outlines the “overloadability” of

the core operators.



Table 12-1.

Overloadability of C# Operators


Download 21,46 Mb.

Do'stlaringiz bilan baham:
1   ...   763   764   765   766   767   768   769   770   ...   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