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


// Build a query expression using extension methods



Download 21,46 Mb.
Pdf ko'rish
bet908/1830
Sana28.09.2021
Hajmi21,46 Mb.
#188411
1   ...   904   905   906   907   908   909   910   911   ...   1830
Bog'liq
[book] [en] Pro C# 2008 and the NET 3.5 Platform Fourth Edition

// Build a query expression using extension methods

// granted to the Array via the Enumerable type.

var subset = currentVideoGames.Where(game => game.Length > 6)

.OrderBy(game => game).Select(game => game);

// Print out the results.

foreach (var game in subset)

Console.WriteLine("Item: {0}", game);

Console.WriteLine();

}

Here, we are calling the generic Where() method off the string array object, granted to the Array



type as an extension method defined by Enumerable. The Enumerable.Where() method makes use

of the System.Func delegate type. The first type parameter of this delegate represents

C H A P T E R   1 4  

A N   I N T R O D U C T I O N  TO   L I N Q



460

8849CH14.qxd  9/26/07  12:30 PM  Page 460




the IEnumerable-compatible data to process (an array of strings in this case), while the second

type parameter represents the method that will process said data.

Given that we have opted for a lambda expression (rather than directly creating an instance

of Func or crafting an anonymous method), we are specifying that the “game” parameter is

processed by the statement game.Length > 6, which results in a Boolean return type.

The return value of the Where() method has implicitly typed, but under the covers we are

operating on an OrderedEnumerable type. From this resulting object, we call the generic OrderBy

K>() method, which also requires a Func delegate parameter. Finally, from the result of the

specified lambda expression, we select each element, using once again a Func under the

covers.


It is also worth remembering that extension methods are unique in that they can be called as

instance-level members upon the type they are extending (System.Array in this case) or as static

members using the type they were defined within. Given this, we could also author our query

expression as follows:

var subset = Enumerable.Where(currentVideoGames, game => game.Length > 6)

.OrderBy(game => game).Select(game => game);

As you may agree, building a LINQ query expression using the methods of the Enumerable type

directly is much more verbose than making use of the C# query operators. As well, given that the

methods of Enumerable require delegates as parameters, you will typically need to author lambda

expressions to allow the input data to be processed by the underlying delegate target.




Download 21,46 Mb.

Do'stlaringiz bilan baham:
1   ...   904   905   906   907   908   909   910   911   ...   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