C# Array Length
To get the length of an Array in C#, read Length property of this Array. Length is a read only property that returns the number of elements in the Array.
Example
In the following example, we take an array in a variable arr
, find its length, and print this length to console.
Program.cs
</>
Copy
using System;
namespace CSharpExamples {
class Program {
static void Main(string[] args) {
string[] arr = {"apple", "banana", "cherry"};
int len = arr.Length;
Console.WriteLine("Length of array : "+len);
}
}
}
Output
Length of array : 3
Conclusion
In this C# Tutorial, we learned how to find the length of an array using Array.Length property.