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);
}
}
Type 'object' does not contain a definition for 'name' and no extension method 'name' of type 'object' could be found (are you missing a using directive or an assembly reference?)
如果'people'只包含「People」類型的對象,那麼最好將它聲明爲'List'而不是'ArrayList' –
Ahmad說的是正確的,'ArrayList'是一個非常古老的類,並且幾乎在每種情況下都應該使用'List'。事實上,大多數人在需要時使用'List