C# 0 The Complete Reference



Download 4,07 Mb.
Pdf ko'rish
bet714/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   710   711   712   713   714   715   716   717   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

items

.

The



items

 array contains objects of type 



Item

, which encapsulate a name and a number for 

an inventory item.

Next comes the 



join

 clause shown here:

join entry in statusList

  on item.ItemNumber equals entry.ItemNumber

This clause specifies that 

entry

 is the range variable for the 



statusList

 data source. The 



statusList

 array contains objects of type 



InStockStatus

, which link an item number with 

its status. Thus, 

items

 and 


statusList

 have a property in common: the item number. This 

is used by the 

on

/

equals

 portion of the 

join

 clause to describe the correlation. Thus, 



join

matches items from the two data sources when their item numbers are equal.

Finally, the 

select

 clause returns a 



Temp

 object that contains an item’s name along with 

its in-stock status:

www.freepdf-books.com




PART I

C h a p t e r   1 9 :  

L I N Q  

569


PART IPART I

select new Temp(item.Name, entry.InStock);

Therefore, the sequence obtained by the query consists of 

Temp

 objects.

Although the preceding example is fairly straightforward, 

join

 supports substantially 

more sophisticated operations. For example, you can use 

into

 with 


join

 to create a 



group

join,

 which creates a result that consists of an element from the first sequence and a group of 

all matching elements from the second sequence. (You’ll see an example of this a bit later in 

this chapter.) In general, the time and effort needed to fully master 



join

 is well worth the 

investment because it gives you the ability to reorganize data at runtime. This is a powerful 

capability. This capability is made even more powerful by the use of anonymous types, 

described in the next section.

Anonymous Types

C# 3.0 adds a new feature called the 



anonymous type

 that directly relates to LINQ. As the 

name implies, an anonymous type is a class that has no name. Its primary use is to create an 

object returned by the 



select

 clause. Often, the outcome of a query is a sequence of objects 

that are either a composite of two (or more) data sources (such as in the case of 

join

) or 


include a subset of the members of one data source. In either case, often the type of the 

object being returned is needed only because of the query and is not used elsewhere in the 

program. In this case, using an anonymous type eliminates the need to declare a class that 

will be used simply to hold the outcome of the query.

An anonymous type is created through the use of this general form:

new { 


nameA

 = 


valueA

,

nameB

 = 

valueB

, ... }


Here, the names specify identifiers that translate into read-only properties that are 

initialized by the values. For example,

new { Count = 10, Max = 100, Min = 0 }

This creates a class type that has three public read-only properties: 




Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   710   711   712   713   714   715   716   717   ...   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