C# 0 The Complete Reference



Download 4,07 Mb.
Pdf ko'rish
bet704/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   700   701   702   703   704   705   706   707   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

.org

 or 

.com

.

// Demonstrate the group clause.



using System;

using System.Linq;

class GroupDemo {

  static void Main() {

www.freepdf-books.com



562

 

P a r t   I :  



T h e   C #   L a n g u a g e

    string[] websites = { "hsNameA.com", "hsNameB.net", "hsNameC.net",

                          "hsNameD.com", "hsNameE.org", "hsNameF.org",

                          "hsNameG.tv",  "hsNameH.net", "hsNameI.tv" };

    // Create a query that groups websites by top-level domain name.

    var webAddrs = from addr in websites

                   where addr.LastIndexOf(".") != -1

                   group addr by addr.Substring(addr.LastIndexOf("."));

    // Execute the query and display the results.

    foreach(var sites in webAddrs) {

      Console.WriteLine("Web sites grouped by " + sites.Key);

      foreach(var site in sites)

        Console.WriteLine("  " + site);

      Console.WriteLine();

    }

  }


}

The output is shown here:

Web sites grouped by .com

  hsNameA.com

  hsNameD.com

Web sites grouped by .net

  hsNameB.net

  hsNameC.net

  hsNameH.net

Web sites grouped by .org

  hsNameE.org

  hsNameF.org

Web sites grouped by .tv

  hsNameG.tv

  hsNameI.tv

As the output shows, the data is grouped based on the top-level domain name of a 

website. Notice how this is achieved by the 

group

 clause:


var webAddrs = from addr in websites

               where addr.LastIndexOf(".") != -1

               group addr by addr.Substring(addr.LastIndexOf("."));

The key is obtained by use of the 




Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   700   701   702   703   704   705   706   707   ...   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