Cannot apply indexing with [] to an expression of type `object'

前端 未结 4 1536
梦如初夏
梦如初夏 2021-01-04 04:17

Here is my code: An ArrayList of ArrayList that returns a float:

public ArrayList walls=new ArrayList(); 

public void Start()
{
    walls[0         


        
4条回答
  •  北荒
    北荒 (楼主)
    2021-01-04 04:53

    Where are you doing the casting?

    I would say it must be (did not try with a compiler):

    for (int i = 0; i < paredes.Length; i++)
    {           
        float a=(float)((ArrayList)paredes[i])[0];
        ...                   
    }
    

    Did you consider using the generic collections instead?

    public List> paredes = new List>();   
    

提交回复
热议问题