C# 0 The Complete Reference



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

Count

 and 


Str

 are given the specified initial values.

It is important to understand that the order of the initializers is not important. For 

example,


obj

 could have been initialized as shown here:

MyClass obj = new MyClass { Str = "Testing", Count = 100 };

In this statement, the initialization of 



Str

 precedes the initialization of 



Count

. In the program, 

it was the other way around. However, in either case, the end result is the same.

Here is the general form of object initialization syntax:

new

class-nam

e { 


name

 = 


expr

,

name

 = 

expr

,

name

 = 

expr

, ... }


Here, 

name

 specifies the name of a field or property that is an accessible member of 



class-

name

. Of course, the type of the initializing expression specified by 



expr

 must be compatible 

with the type of field or property.

Although you can use object initializers with a named class (such as 



MyClass

 in the 


example), you usually won’t. In general, you will use the normal constructor call syntax 

when working with named classes. As mentioned, object initializers are most applicable 

to anonymous types generated by a LINQ expression.


Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   270   271   272   273   274   275   276   277   ...   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