Original Post
Hey all. I'm returning to game coding after a long absence, and have switched to C# and XNA on the grounds that it makes everything a million times easier for a hobby coder such as myself. However, from what I am reading, pointers are something to be avoided in C# where possible. I've read that "unsafe" code isn't as ominous as it sounds, but all the same... So, there are a couple of things I would do with pointers in C++ that I am wondering how to replicate in C#. The first would be allowing objects to "target" other objects. This could be a heat seeking missile that would have previously given a pointer to it's target, or a player that is given a list of pointers to objects in his inventory. I thought about tracking the objects by their place/index in the linked list (eg, missile target = int targetindex where targetindex is the target enemies position in a list) but when objects get removed from the list these indexes change. Is the solution to just add code to keep up with these changes (eg, whenever something is deleted before the missiles target, have a function iterate through the list and change any out of date indexes). The other problems was with derived/child classes. I want to have an array of physical objects that behave the same way in many respects (eg, collisions and physics) and reside in the same list. However, special objects like players need to be handled differently. In C++ I would make an array of pointers to the players, and iterate through it to perform special player code like input. How can I replicated this in C#? Is it a case of going through the list and finding index entries to the player's objects?