C# 0 The Complete Reference



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

Expression Lambdas

In an expression lambda, the expression on the right side of the 



=>

 acts on the parameter (or 

parameters) specified by the left side. The result of the expression becomes the result of the 

lambda operator and is returned.

Here is the general form of an expression lambda that takes only one parameter:

param

 => 


expr

When more than one parameter is required, then the following form is used:

(

param-list

) => 


expr

Therefore, when two or more parameters are needed, they must be enclosed by parentheses. 

If no parameters are needed, then empty parentheses must be used.

Here is a simple expression lambda:

count => count + 2

Here 


count

 is the parameter that is acted on by the expression 



count + 2

. Thus, the result is 

the value of 

count

 increased by two. Here is another example:

n => n % 2 == 0

In this case, this expression returns true if 



n

 is even and false if it is odd.

To use a lambda expression involves two steps. First, declare a delegate type that 

is compatible with the lambda expression. Second, declare an instance of the delegate, 

assigning to it the lambda expression. Once this has been done, the lambda expression can 

be executed by calling the delegate instance. The result of the lambda expression becomes 

the return value.

The following program shows how to put the two expression lambdas just shown into 

action. It declares two delegate types. The first, called 


Download 4,07 Mb.

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