C# Program to Find the Length of Jagged Array using Predefined Functions

This is a C# Program to find the length of the jagged array using predefined functions.

Problem Description

This C# Program Finds the Length of the Jagged Array using Predefined Functions.

Problem Solution

Here the Length of each row in the jagged array is calculated and displayed.

Program/Source Code

Here is source code of the C# Program to Find the Length of the Jagged Array using Predefined Functions. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.

/*
 * C# Program to Find the Length of the Jagged Array using Predefined Functions
 */
using System;
class Program
{
    public static void Main()
    {
        byte[][] numbers = new byte[5][];
        for (int i = 0; i < numbers.Length; i++)
        {
            numbers[i] = new byte[i + 3];
        }
        for (int i = 0; i < numbers.Length; i++)
        {
            Console.WriteLine("Length of row {0} is {1}", i, numbers[i].Length);
        }
        Console.Read();
    }
}
Program Explanation

This C# program is used to find the length of the jagged array using predefined functions. A jagged array is an array whose elements are arrays. The elements of a jagged array can be of different dimensions and sizes.

advertisement
advertisement

A jagged array is sometimes called an “array of arrays.” The following examples show how to declare, initialize, and access jagged arrays. For loop is used to assign an element value starting with 3 for an array. Hence another for loop is used to print the elements of an array.

Runtime Test Cases
 
Length of row 0 is 3
Length of row 1 is 4
Length of row 2 is 5
Length of row 3 is 6
Length of row 4 is 7

Sanfoundry Global Education & Learning Series – 1000 C# Programs.

Note: Join free Sanfoundry classes at Telegram or Youtube
If you wish to look at all C# Programming examples, go to 1000 C# Programs.

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.