C# 0 The Complete Reference


Using Length with Jagged Arrays



Download 4,07 Mb.
Pdf ko'rish
bet213/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   209   210   211   212   213   214   215   216   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

Using Length with Jagged Arrays

A special case occurs when 



Length

 is used with jagged arrays. In this situation, it is possible 

to obtain the length of each individual array. For example, consider the following program

which simulates the CPU activity on a network with four nodes:

// Demonstrate Length with jagged arrays.

using System;

class Jagged {

  static void Main() {

    int[][] network_nodes = new int[4][];

    network_nodes[0] = new int[3];

    network_nodes[1] = new int[7];

    network_nodes[2] = new int[2];

    network_nodes[3] = new int[5];

    int i, j;

    // Fabricate some fake CPU usage data.

    for(i=0; i < network_nodes.Length; i++)

      for(j=0; j < network_nodes[i].Length; j++)

        network_nodes[i][j] = i * j + 70;

    Console.WriteLine("Total number of network nodes: " +

                      network_nodes.Length + "\n");

    for(i=0; i < network_nodes.Length; i++) {

      for(j=0; j < network_nodes[i].Length; j++) {

        Console.Write("CPU usage at node " + i +

                      " CPU " + j + ": ");

        Console.Write(network_nodes[i][j] + "% ");

        Console.WriteLine();

      }

      Console.WriteLine();

    }

  }


}

The output is shown here:

Total number of network nodes: 4

CPU usage at node 0 CPU 0: 70%

CPU usage at node 0 CPU 1: 70%

CPU usage at node 0 CPU 2: 70%

CPU usage at node 1 CPU 0: 70%

CPU usage at node 1 CPU 1: 71%

CPU usage at node 1 CPU 2: 72%

CPU usage at node 1 CPU 3: 73%

CPU usage at node 1 CPU 4: 74%

www.freepdf-books.com




Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   209   210   211   212   213   214   215   216   ...   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