InterviewSolution
Saved Bookmarks
| 1. |
Define the rank of an array in C# |
|
Answer» The rank of an array is the number of dimensions of an array. For EXAMPLE - The rank of a one-dimensional array is 1, the rank of a TWO dimensional array is 2 and so on. The rank of a jagged array is 1 as it is a one-dimensional array. The rank of any array can be found using the Array.Rank property. A program that demonstrates the rank of an array in C# is given as follows: using System; namespace Demo { class Program { static void Main(string[] ARGS) { int[] arr1 = new int[10]; int[,] ARR2 = new int[4, 5]; int[][] arr3 = new int[5][]; Console.WriteLine("Rank of Array 1 is: " + arr1.Rank); Console.WriteLine("Rank of Array 2 is: " + arr2.Rank); Console.WriteLine("Rank of Array 3 is: " + arr3.Rank); } } }The output of the above program is as follows: Rank of Array 1 is: 1 Rank of Array 2 is: 2 Rank of Array 3 is: 1 |
|