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



Download 21,46 Mb.
Pdf ko'rish
bet921/1830
Sana28.09.2021
Hajmi21,46 Mb.
#188411
1   ...   917   918   919   920   921   922   923   924   ...   1830
Bog'liq
[book] [en] Pro C# 2008 and the NET 3.5 Platform Fourth Edition

// Order all the cars by PetName.

var subset = from c in myCars orderby c.PetName select c;

Console.WriteLine("Ordered by PetName:");

foreach (Car c in subset)

{

Console.WriteLine(c.ToString());



}

// Now find the cars that are going less than 55 mph,

// and order by descending PetName

subset = from c in myCars

where c.Speed > 55 orderby  c.PetName descending select c;

Console.WriteLine("\nCars going faster than 55, ordered by PetName:");

foreach (Car c in subset)

{

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



468

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




Console.WriteLine(c.ToString());

}

}



Although ascending order is the default, you are able to make your intentions very clear by

making use of the ascending operator:

var subset = from c in myCars

orderby c.PetName ascending select c;

Given these examples, you can now understand the format of a basic sorting query expression

as follows:

var result = from item in container orderby value

ascending/descending select item;

Finding Differences

The last LINQ query we will examine for the time being involves obtaining a result set that deter-

mines the differences between two IEnumerable compatible containers. Consider the following

method, which makes use of the Enumerable.Except() method to yield (in this example) a Yugo:

static void GetDiff()

{

List myCars = new List



{ "Yugo", "Aztec", "BMW"};

List yourCars = new List

{ "BMW", "Saab", "Aztec" };

var carDiff =(from c in myCars select c)

.Except(from c2 in yourCars select c2);

Console.WriteLine("Here is what you don't have, but I do:");

foreach (string s in carDiff)

Console.WriteLine(s);  // Prints Yugo.

}

These examples should give you enough knowledge to feel comfortable with the process of



building LINQ query expressions. Chapter 24 will explore the related topics of LINQ to ADO (which

is a catch-all term describing LINQ to SQL and LINQ to DataSet) and LINQ to XML. However, before

wrapping the current chapter, let’s examine the topic LINQ queries as method return values.


Download 21,46 Mb.

Do'stlaringiz bilan baham:
1   ...   917   918   919   920   921   922   923   924   ...   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