C# 0 The Complete Reference


Auto-Implemented Properties



Download 4,07 Mb.
Pdf ko'rish
bet340/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   336   337   338   339   340   341   342   343   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

Auto-Implemented Properties

Beginning with C# 3.0, it is possible to implement very simple properties without having 

to explicitly define the variable managed by the property. Instead, you can let the compiler 

automatically supply the underlying variable. This is called an 



auto-implemented property. 

It

has the following general form:



type name

 { get; set; }

Here, 

type

 specifies the type of the property and 



name

 specifies the name. Notice that 



get

and


set

 are immediately followed by a semicolon. The accessors for an auto-implemented 

property have no bodies. This syntax tells the compiler to automatically create a storage 

location (sometimes referred to as a 



backing field

) that holds the value. This variable is not 

named and is not directly available to you. Instead, it can be accessed only through the 

property.

www.freepdf-books.com



260

 

P a r t   I :  



T h e   C #   L a n g u a g e

Here is how a property called 



UserCount

 is declared using an auto-implemented 

property:

public int UserCount { get; set; }

Notice that no variable is explicitly declared. As explained, the compiler automatically 

generates an anonymous field that holds the value. Otherwise, 



UserCount

 acts like and is 

used like any other property.

Unlike normal properties, an auto-implemented property cannot be read-only or write-

only. Both the 


Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   336   337   338   339   340   341   342   343   ...   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