Version: 2020.1

描述

长度属性,可返回或设置 Array 中的元素数量。

使用 Array.length 获取或设置数组的大小。以下示例使用 C# Length 属性。

// 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); } }