C# 0 The Complete Reference



Download 4,07 Mb.
Pdf ko'rish
bet361/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   357   358   359   360   361   362   363   364   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

Width

 and 


Height

 inside the 



Area( )

 method is illegal. Since 



Width

 and 


Height

 are now private, they are accessible only 

to other members of their own class. Derived classes have no access to them.

R

EMEMBER

R

EMEMBER

A private class member will remain private to its class. It is not accessible to any code 

outside its class, including derived classes.

At first, you might think that it is a serious restriction that derived classes do not have 

access to the private members of base classes because it would prevent the use of private 

members in many situations. However, this is not true; C# provides various solutions. One 

is to use 

protected

 members, which is described in the next section. A second is to use public 

properties to provide access to private data.

As explained in the previous chapter, a property allows you to manage access to an 

instance variable. For example, you can enforce constraints on its values, or you can make 

the variable read-only. By making a property public, but declaring its underlying variable 

private, a derived class can still use the property, but it cannot directly access the underlying 

private variable.

Here is a rewrite of the 


Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   357   358   359   360   361   362   363   364   ...   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