C# 0 The Complete Reference


count  is called in  Main( )



Download 4,07 Mb.
Pdf ko'rish
bet525/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   521   522   523   524   525   526   527   528   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

count

 is called in 



Main( )

.

Although captured variables can result in rather counterintuitive situations, such as the 



one just shown, it makes sense if you think about it a bit. The key point is that when an 

anonymous method captures a variable, that variable cannot go out of existence until the 

delegate that captures it is no longer being used. If this were not the case, then the captured 

variable could be undefined when it is needed by the delegate.



Lambda Expressions

Although anonymous methods are a valuable feature, they have been largely superceded 

by a better approach: the 

lambda expression.

 It is not an overstatement to say that the lambda 

expression is one of the two most important features added by C# 3.0 (the other being LINQ). 

Based on an entirely new syntactic element, the lambda expression provides a powerful 

alternative to the anonymous method. Although a principal use of lambda expressions is 

found when working with LINQ (see Chapter 19), they are also applicable to (and commonly 

used with) delegates and events. This use of lambda expressions is described here.

A lambda expression is the second way that an anonymous function can be created. 

(The other type of anonymous function is the anonymous method, described in the 

preceding section.) Thus, a lambda expression can be assigned to a delegate. Because a 

lambda expression is more streamlined than the equivalent anonymous method, lambda 

expressions are now the recommended approach in almost all cases.




Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   521   522   523   524   525   526   527   528   ...   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