c# – 无法将带有[]的索引应用于类型为`object’的表达式

前端之家收集整理的这篇文章主要介绍了c# – 无法将带有[]的索引应用于类型为`object’的表达式前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
这是我的代码:ArrayList的ArrayList,它返回一个float:
public ArrayList paredes=new ArrayList();   

public void Start()
{
    paredes[0] = RetornaEmArrayList(279,275,90);
    paredes[1] = RetornaEmArrayList(62,0);
    paredes[2] = RetornaEmArrayList(62,62,90);
    paredes[3] = RetornaEmArrayList(217,-62,0);
    paredes[4] = RetornaEmArrayList(62,279,90);
    paredes[5] = RetornaEmArrayList(41,0);
    paredes[6] = RetornaEmArrayList(279,320,9);
    paredes[7] = RetornaEmArrayList(320,-279,0);  

    for (int i = 0; i < paredes.Length; i++) {
        float a = (float)paredes[i][0];
        float b = (float)paredes[i][1];
        float c = (float)paredes[i][2];
        float d = (float)paredes[i][3];
        float e = (float)paredes[i][4];
    }
}

ArrayList RetornaEmArrayList(float a,float b,float c,float d,float e)
{
    ArrayList arrayList = new ArrayList();
    arrayList.Add(a);
    arrayList.Add(b);
    arrayList.Add(c);
    arrayList.Add(d);
    arrayList.Add(e);
    return arrayList;
}

它给了我以下错误

error CS0021: Cannot apply indexing with [] to an expression of type
`object’

我已经做了铸造,出了什么问题? 原文链接:https://www.f2er.com/csharp/92165.html

猜你在找的C#相关文章