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

  • SEARCH
  • Home
  • 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 8968399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:26:54+00:00 2026-06-15T17:26:54+00:00

First of all, it was difficult to find a proper title for my question…

  • 0

First of all, it was difficult to find a proper title for my question… sorry in advance for this.

I am facing an issue with C# .NET. I’ll try to simplify it with a temporary example.

I have three classes:

book
movie_dvd
game_dvd

each of them have the same base properties such: id and name. We can however suppose they have other different properties and different methods to be the same class. They can of course be children of a parent class to make it better.

Then I create List of each of these classes to define my collection of books, movies and games. Their id property is of course matched with the key of the List, and as I insert each item in the List I give them an appropriate name (their title).

I have a main winForm with 3 buttons: “Show Books Collection”, “Show Movies Collection” and “Show Games Collection”. The user can click one of them, and then another window appear and show the passed collection inside a ListBox (or whatever).

Now here’s my problem.

Right now I’m creating three separate (but almost identical) WinForms to display the content of each collection (books, movies, games), which I think is greatly overdoing things. What I would really like to do is create a single window to display the content of any of these collections. The problem is that if I pass a book object/class inside the parameters of the new winForm, on the other side it expects to be a book object.

How can I use a single Winform to display the title of each of these differnt objects without duplicating the WinForm code over and over?

  • 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-15T17:26:55+00:00Added an answer on June 15, 2026 at 5:26 pm

    If each of these objects will have the same properties (e.g. Title) then you create a base class with those properties. You could then create more specific properties in the derived classes.

    public abstract class MediaBase
    {
        public String Title { get; set; }
        public Int32 Id { get; set; }
    }
    
    public sealed class Book : MediaBase
    {
        public String Author { get; set; }
        public Int32 Pages { get; set; }
    }
    
    public sealed class MovieDvd : MediaBase
    {
        public String Director { get; set; }
        public Int32 Length { get; set; }
    }
    
    public sealed class GameDvd : MediaBase
    {
        public Int32 NumberOfPlayers { get; set; }
    }
    

    Or you could pass the parameters as objects and then cast them back into their actual type.

    if (parameter is book)
    {
        book theBook = ((book)parameter);
    }
    else if (parameter is movie_dvd)
    {
        movie_dvd movieDvd = ((movie_dvd)parameter);
    }
    else if (parameter is game_dvd)
    {
        game_dvd gameDvd = ((game_dvd)parameter);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

first of all I apologize if my question is difficult to understand. I'm having
First of all there is probably a question like this already but i couldn't
Good morning, all. This is my first question on stackoverflow, so hopefully this isn't
First of all, this isn't for a keylogger, it's for an input in a
First of all, apologize because I have seen some posts about this, but I
this is yet another OpenCV installation question, however I wasn't able to find an
I've been trying to build this small java app. I find it very difficult
First of all, thanks in advance for your attention : I am pretty noob
I saw variants of this question before, but didn't find answer yet. I have
First of all I am not really good in english but Ill try to

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.