You can use the Length property of the array to return the number of elements in it. Note that once the array is created , you cannot change its length.
How to get the Number of Elements in an Array in C# ?
Here’s a code snippet demonstrating the usage of the Length property of the array to get the number of elements.
using System;
namespace ACConsoleApp1
{
class Program
{
static void Main(string[] args)
{
int[] arr = new int[] { 10, 8, 81, 11, 23,46 };
// Get the number of elemnts in an array.
var arrayLength = arr.Length;
Console.WriteLine("The length of the array is : "+ arrayLength);
Console.ReadLine();
}
}
}
1 Comment