C# 0 The Complete Reference


PART I C h a p t e r   1 9



Download 4,07 Mb.
Pdf ko'rish
bet730/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   726   727   728   729   730   731   732   733   ...   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  

579


PART IPART I

The minimum value is 1

The maximum value is 5

The first value is 3

The last value is 4

The sum is 15

The average is 3

All values are greater than zero.

At least one value is even.

The array contains 3.

You can also use the query-related extension methods within a query based on the C# 

query syntax. In fact, it is quite common to do so. For example, this program uses 



Average( )

to obtain a sequence that contains only those values that are less than the average of the 

values in an array.

// Use Average() with the query syntax.

using System;

using System.Linq;

class ExtMethods2 {

  static void Main() {

    int[] nums =  { 1, 2, 4, 8, 6, 9, 10, 3, 6, 7 };

    var ltAvg = from n in nums

                let x = nums.Average()

                where n < x

                select n;

    Console.WriteLine("The average is " + nums.Average());

    Console.Write("These values are less than the average: ");

    // Execute the query and display the results.

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

    Console.WriteLine();

  }

}

The output is shown here:



The average is 5.6

These values are less than the average: 1 2 4 3

Pay special attention to the query:

    var ltAvg = from n in nums

                let x = nums.Average()

                where n < x

                select n;

Notice in the 




Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   726   727   728   729   730   731   732   733   ...   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