.Length
Published Nov 3, 2022Updated May 24, 2023
Contribute to Docs
The .Length
property returns the total number of elements in the array, including all dimensions of the array.
Syntax
int myLength = myArray.Length;
myArray.Length
returns an int
that represents the number of elements in myArray
.
Example
The following example initializes an array, then prints out the number of elements it contains:
using System;public class Example{public static void Main(string[] args){int[] myArray = {0, 1, 2, 3, 4};Console.WriteLine(myArray.Length); // Output: 5}}
Codebyte Example
The following runnable code uses the .Length
property to return the length of the numbers
array:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn C# on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Free course
Learn C#
Learn Microsoft's popular C# programming language, used to make websites, mobile apps, video games, VR, and more.Beginner Friendly23 hours