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


// Object users can only get the value, however



Download 21,46 Mb.
Pdf ko'rish
bet363/1830
Sana28.09.2021
Hajmi21,46 Mb.
#188411
1   ...   359   360   361   362   363   364   365   366   ...   1830
Bog'liq
[book] [en] Pro C# 2008 and the NET 3.5 Platform Fourth Edition

// Object users can only get the value, however

// the Employee class and derived types can set the value.

public string SocialSecurityNumber

{

get { return empSSN; }



protected set { empSSN = value; }

}

In this case, the set logic of SocialSecurityNumber can only be called by the current class and



derived classes and therefore cannot be called from an object instance. Again, the protected

keyword will be formally detailed in the next chapter when we examine inheritance and poly-

morphism.

Read-Only and Write-Only Properties

When encapsulating data, you may wish to configure a read-only property. To do so, simply omit the

set block. Likewise, if you wish to have a write-only property, omit the get block. For example, here

is how the SocialSecurityNumber property could be retrofitted as read-only:

public string SocialSecurityNumber

{

get { return empSSN; }



}

Given this adjustment, the only manner in which an employee’s US Social Security number can

be set is through a constructor argument. Therefore it would now be a compiler error to attempt to

set an employee’s SSN value as so:

static void Main(string[] args)

{

Console.WriteLine("***** Fun with Encapsulation *****\n");



Employee emp = new Employee("Marvin", 24, 456, 30000, "111-11-1111");

emp.GiveBonus(1000);

emp.DisplayStats();


Download 21,46 Mb.

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