Version: 2019.2
LanguageEnglish
  • C#

Array.length

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

The length property that returns or sets the number of elements in the Array.

Use Array.length to get or set the size of the array. The example uses the C# Length property.

// C# array Length example
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { void Start() { // use string array approach string[] names = new string[] {"Hello", "World", "Really"};

foreach (string s in names) { print("user is: " + s); }

print("length is: " + names.Length);

// use ArrayList approach ArrayList arr = new ArrayList(); arr.Add("Hello"); arr.Add("World");

// ArrayList uses Count instead of Length print(arr.Count); } }