Sign in to follow this  

[.net] Quick question about C# Array List

This topic is 4303 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi i have an array list of gameobjects. I am trying to access just the first element in this list. I have tried theObjects[0].doSomething() however this brings back the error: 'object does not contain definition for doSomthing' - i assume this is because arrayList just contains a base object class which every other object type inherits from - So i tried casting as such: (GameObject)theObjects[0].doSomething() but this brings up the same error. Any ideas? Thanks

Share this post


Link to post
Share on other sites
So the syntax you're looking for is:
((GameObject)theObjects[0]).doSomething()

However, if at all possible, please use the .NET 2.0 framework so that you can have access to Generic lists.

List<GameObject> theObjects = new List<GameObject>();
..
theObjects[0].doSomething()

:-)

Share this post


Link to post
Share on other sites
Sign in to follow this