using UnityEngine;
using System.Collections;
public class People{
public string name;
public int type;
}
public class Game{
public ArrayList people;
public void start(){
People p = new People();
p.name = "Vitor";
p.type = 1;
people = new ArrayList ();
people.add(p);
Debug.Log(p[0].name);
}
}
Run Code Online (Sandbox Code Playgroud)
返回错误:
类型'object'不包含'name'的定义,也没有找到'object'类型的扩展方法'name'(你是否缺少using指令或程序集引用?)
在ArrayList由对象,所以你需要将其强制转换:
Debug.Log(((People)people[0]).name);
Run Code Online (Sandbox Code Playgroud)