C# 0 The Complete Reference


PART I C h a p t e r   1 9



Download 4,07 Mb.
Pdf ko'rish
bet687/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   683   684   685   686   687   688   689   690   ...   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  

549


PART IPART I

class SimpQuery {

  static void Main() {

    int[] nums =  { 1, -2, 3, 0, -4, 5 };

    // Create a query that obtains only positive numbers.

    var posNums = from n in nums

                  where n > 0

                  select n;

    Console.Write("The positive values in nums: ");

    // Execute the query and display the results.

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

    Console.WriteLine();

    // Change nums.

    Console.WriteLine("\nSetting nums[1] to 99.");

    nums[1] = 99;

    Console.Write("The positive values in nums after change: ");

    // Execute the query a second time.

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

    Console.WriteLine();

  }


}

The following output is produced:

The positive values in nums: 1 3 5

Setting nums[1] to 99.

The positive values in nums after change: 1 99 3 5

As the output confirms, after the value in 



nums[1]

was changed from –2 to 99, the result 

of rerunning the query reflects the change. This is a key point that must be emphasized. 

Each execution of a query produces its own results, which are obtained by enumerating the 

current contents of the data source. Therefore, if the data source changes, so, too, might the 

results of executing a query. The benefits of this approach are quite significant. For example, 

if you are obtaining a list of pending orders for an online store, then you want each execution 

of your query to produce all orders, including those just entered.




Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   683   684   685   686   687   688   689   690   ...   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