C# 0 The Complete Reference


PART I C h a p t e r   1 9



Download 4,07 Mb.
Pdf ko'rish
bet697/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   693   694   695   696   697   698   699   700   ...   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  

557


PART IPART I

    double[] nums =  { -10.0, 16.4, 12.125, 100.85, -2.2, 25.25, -3.5 } ;

    // Create a query that returns the square roots of the

    // positive values in nums.

    var sqrRoots = from n in nums

                   where n > 0

                   select Math.Sqrt(n);

    Console.WriteLine("The square roots of the positive values" +

                      " rounded to two decimal places:");

    // Execute the query and display the results.

    foreach(double r in sqrRoots) Console.WriteLine("{0:#.##}", r);

  }


}

The output is shown here:

The square roots of the positive values rounded to two decimal places:

4.05


3.48

10.04


5.02

In the query, pay special attention to the 



select

 clause:


select Math.Sqrt(n);

It returns the square root of the range variable. It does this by obtaining the result of passing 

the range variable to 

Math.Sqrt( )

, which returns the square root of its argument. This means 

that the sequence obtained when the query is executed will contain the square roots of the 

positive values in 



nums

. If you generalize this concept, the power of 



select

 becomes apparent. 

You can use 

select

 to generate any type of sequence you need, based on the values obtained 

from the data source.

Here is a program that shows another way to use 




Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   693   694   695   696   697   698   699   700   ...   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