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.
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.
Output:
Explanation:
In the above program, we created a Demo class that contains the Main() method. Here we created a jagged array of strings.
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.