C# 0 The Complete Reference



Download 4,07 Mb.
Pdf ko'rish
bet685/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   681   682   683   684   685   686   687   688   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

n

 in 


nums

 when the query executes. Only those values that satisfy this 

condition will be obtained. In other words, a 

where

 clause acts as a filter on the data source, 

allowing only certain items through.

All queries end with either a 



select

 clause or a 



group

 clause. This example employs the 



select

 clause. It specifies precisely what is obtained by the query. For simple queries, such as 

the one in this example, the range value is selected. Therefore, it returns those integers from 

nums

 that satisfy the 



where

 clause. In more sophisticated situations, it is possible to finely 

tune what is selected. For example, when querying a mailing list, you might return just the 

last name of each recipient, rather than the entire address. Notice that the 



select

 clause ends 

with a semicolon. Because 

select

 ends a query, it ends the statement and requires a semicolon. 

Notice, however, that the other clauses in the query do not end with a semicolon.

At this point, a query variable called 



posNums

 has been created, but no results have 

been obtained. It is important to understand that a query simply defines a set of rules. It is 

not until the query is executed that results are obtained. Furthermore, the same query can 

be executed two or more times, with the possibility of differing results if the underlying 

data source changes between executions. Therefore, simply declaring the query 



posNums

does not mean that it contains the results of the query.

To execute the query, the program uses the 

foreach

 loop shown here:

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

Notice that 



posNums

 is specified as the collection being iterated over. When the 



foreach

executes, the rules defined by the query specified by 



posNums

 are executed. With each pass 

through the loop, the next element returned by the query is obtained. The process ends when 

there are no more elements to retrieve. In this case, the type of the iteration variable 



i

 is 


explicitly specified as 

int

 because this is the type of the elements retrieved by the query. 

Explicitly specifying the type of the iteration variable is fine in this situation, since it is easy 

to know the type of the value selected by the query. However, in more complicated situations, 

it will be easier (or in some cases, necessary) to implicitly specify the type of the iteration 

variable by using 




Download 4,07 Mb.

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