C# 0 The Complete Reference


XYCoord  class, the only constructor that actually  initializes the  x



Download 4,07 Mb.
Pdf ko'rish
bet271/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   267   268   269   270   271   272   273   274   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

XYCoord

 class, the only constructor that actually 

initializes the 

x

 and 


y

 fields is 



XYCoord(int, int)

. The other two constructors simply invoke 



XYCoord(int, int)

 through 



this

. For example, when object 



t1

 is created, its constructor, 



XYCoord( )

, is called. This causes 



this(0, 0)

 to be executed, which in this case translates 

into a call to 

XYCoord(0, 0)

. The creation of 



t2

 works in similar fashion.

www.freepdf-books.com



PART I

C h a p t e r   8 :  

A   C l o s e r   L o o k   a t   M e t h o d s   a n d   C l a s s e s  

199


PART IPART I

One reason why invoking overloaded constructors through 



this

 can be useful is that 

it can prevent the unnecessary duplication of code. In the foregoing example, there is no 

reason for all three constructors to duplicate the same initialization sequence, which the use 

of

this

 avoids. Another advantage is that you can create constructors with implied “default 

arguments” that are used when these arguments are not explicitly specified. For example, 

you could create another 



XYCoord

 constructor as shown here:

public XYCoord(int x) : this(x, x) { }

This constructor automatically defaults the 




Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   267   268   269   270   271   272   273   274   ...   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