Q:

C# program to get the length of a jagged array using predefine property

belongs to collection: C# Basic Programs | array programs

0

C# program to get the length of a jagged array using predefine property

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

The source code to get the length of the jagged array using predefine property is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.

//Program to get the length of a jagged 
//array using predefined property in C#.

using System;

class Demo
{
    public static void Main()
    {
        string [][] jagged = new string[5][];
        int loop=0;

        for (loop = 0; loop < jagged.Length; loop++)
        {
            jagged[loop] = new string[loop+2];
        }
        for (loop = 0; loop < jagged.Length; loop++)
        {
            Console.WriteLine("Size of row {0}->{1}", loop, jagged[loop].Length);
        }
    }
}

Output:

Size of row 0->2
Size of row 1->3
Size of row 2->4
Size of row 3->5
Size of row 4->6
Press any key to continue . . .

Explanation:

In the above program, we created a Demo class that contains the Main() method. Here we created a jagged array of strings.

for (loop = 0; loop < jagged.Length; loop++)
{
    jagged[loop] = new string[loop+2];
}

In the above code we created each row of the jagged array with different sizes, and then print the size of each row on the console screen.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C# Basic Programs | array programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C# program to find the smallest and largest elemen... >>
<< C# program to convert negative values an integer a...