Jump to content
  • Advertisement
Sign in to follow this  
edd1986

[.net] Quick question about C# Array List

This topic is 4552 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
Advertisement
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  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!