As an intro, I create the base Quadtree engine for personal training purposes. I want this engine to be able to work with many different types of shapes (at the moment I'm going with circles and squares), which will move in the window and perform some action in a collision.
Here are my form objects, as I have them so far:
public class QShape { public int x { get; set; } public int y { get; set; } public string colour { get; set; } } public class QCircle : QShape { public int radius; public QCircle(int theRadius, int theX, int theY, string theColour) { this.radius = theRadius; this.x = theX; this.y = theY; this.colour = theColour; } } public class QSquare : QShape { public int sideLength; public QSquare(int theSideLength, int theX, int theY, string theColour) { this.sideLength = theSideLength; this.x = theX; this.y = theY; this.colour = theColour; } }
Now I ask the question how to create a general list ( List<T> QObjectList = new List<T>(); ) in C # so that I can have one list containing all of these different forms that can have different properties (e.g. QCircle has a radius property, and QSquare has a sideLength property)? An example implementation will also be useful.
I just know that there is a stupidly obvious answer to this question, but I will still be grateful for any help. I am trying to return to C #; it obviously was time ...
object list generics c # quadtree
Djentleman
source share