C# 0 The Complete Reference


PART I C h a p t e r   1 9



Download 4,07 Mb.
Pdf ko'rish
bet690/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   686   687   688   689   690   691   692   693   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt


PART I

C h a p t e r   1 9 :  

L I N Q  

551


PART IPART I

clause returns the data by groups, with each group being able to be enumerated individually. 

As the preceding examples have shown, the 

where

 clause specifies criteria that an item 

must meet in order for it to be returned. The remaining clauses help you fine-tune a query. 

The follows sections examine each query clause.



Filter Values with where

As explained



where

 is used to filter the data returned by a query. The preceding examples 

have shown only its simplest form, in which a single condition is used. A key point to 

understand is that you can use 



where

 to filter data based on more than one condition. One 

way to do this is through the use of multiple 

where

 clauses. For example, consider the 

following program that displays only those values in the array that are both positive and 

less than 10:

// Use multiple where clauses.

using System;

using System.Linq;

class TwoWheres {

  static void Main() {

    int[] nums =  { 1, -2, 3, -3, 0, -8, 12, 19, 6, 9, 10 };

    // Create a query that obtains positive values less than 10.

    var posNums = from n in nums

                  where n > 0

                  where n < 10

                  select n;

    Console.Write("The positive values less than 10: ");

    // Execute the query and display the results.

    foreach(int i in posNums) Console.Write (i + " ");

    Console.WriteLine();

  }


}

The output is shown here:

The positive values less than 10: 1 3 6 9

As you can see, only positive values less than 10 are retrieved. This outcome is achieved by 

the use of the following two 


Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   686   687   688   689   690   691   692   693   ...   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