For an XNA engine I’m trying to make myself, I want an array/arraylist of instances that server as my game objects. If all of my game objects are parented to a GameObject class, what’s a way I can do this?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
How about
or
The first will allocate an array with 100 elements and assign the value of the first two elements. The second will create a list where two elements are added.
The
<>indicates thatList<>is a generic type where you can specify the type of the element stored in the list. This creates a strongly typed collection.Compare that to using an
ArrayList:The
ArrayListclass storesObjectreferences and to access an item in the list you have to perform a cast. That is both tedious and error prone and you should always useList<>and notArrayListunless you are developing .NET 1 code.To learn more about generics you can study the C# programming guide on generics on MSDN.