Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8189715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:22:36+00:00 2026-06-07T03:22:36+00:00

By way of an intro, I’m creating a basic Quadtree engine for personal learning

  • 0

By way of an intro, I’m creating a basic Quadtree engine for personal learning purposes. I’m wanting this engine to have the capability of working with many different types of shapes (at the moment I’m going with circles and squares) that will all move around in a window and perform some sort of action when collision occurs.

Here are my shape 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 my question is, how do I create a generic list (List<T> QObjectList = new List<T>();) in C# so I can have one list containing all these various shapes that may have different properties (e.g., QCircle has the “radius” property while QSquare has the “sideLength” property)? An example of implementation would be helpful as well.

I just know that there is a stupidly obvious answer to this question but I’d appreciate any help anyway. I’m trying to get back into C#; it has obviously been a while…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T03:22:37+00:00Added an answer on June 7, 2026 at 3:22 am

    You need to use downcasting

    Store the objects in a list with the base class

     List<QShape> shapes = new List<QShape>
    

    You can then upcast the object safely if you know what it is e.g.

    if(shapes[0] is QSquare)
    {
         QSquare square = (QSquare)shapes[0]
    } 
    

    You can also implicitly downcast objects

    QSquare square = new Square(5,0,0,"Blue");
    QShape shape =  square
    

    For more information read the Upcasting and Downcasting sections here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

By way of an intro, I'm creating a basic Quadtree engine for personal learning
I'm creating a Yahoo! Widget and have done this before without any problems (creating
Intro: I am working on a Car dealer application so I have a table
I am a VB programmer working my way into C#. I learned how to
I'm looking into creating a automated way to check the running version of our
I've created an intro animation to a page I'm working on using jQuery and
Almost every new website seems to have an intro video that tells prospective new
I'm learning to use Netbeans and for my intro pet projects, I don't want
I'm a physicist, and have been learning some programming, and have come across a
Short Intro Currently I have a UITableView which is filled with custom cells that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.