我是新的C#中的ArrayList索引對象的方法,我正在寫一個程序,我有一個ArrayList
(unitArray
)Unit
對象,我試圖呼籲一個non-static
方法在ArrayList
中引用的對象。我嘗試訪問特定對象並調用它的方法,但它不起作用。我會很感謝幫助解決這個問題。試圖調用C#
Unit.unitArray[selectedUnit].DisplayUnitAttributes()
我得到以下異常:
'object' does not contain a definition for 'DisplayUnitAttributes' and no extension method 'DisplayUnitAttributes' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
雖然你有不同的答案了,我想你應該關注的cdiggins THA回答,如果你的'ArrayList'的所有元素都是同一類型的,因爲沒有然後在更常見的'ArrayList'中感知。 – horgh