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 8164443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:19:04+00:00 2026-06-06T19:19:04+00:00

Which I’m trying to accomplish is have two classes, a non generic and a

  • 0

Which I’m trying to accomplish is have two classes, a non generic and a generic.

I need a non generic class because I plan to insert objects of this class and insert them in a List<T>

Here’s the code

// Non-generic
public class Response
{
    public object Value { get; }
}

// Generic
public class Response<T> : Response
{
    public T Value { get; set; }
}

I’d like to have a List<Response>, where when I access to this object I get the Value property as object.

But when I receive this object as generic, access to the T Value property and hide the object Value property.

I hope be clear, if not.. please let me know.

EDIT: This is for a quiz. So, each question has answers.. For example in MultipleChoiceQuestion, it could have several answers A, B, C, D as view shapes, or could be strings, or integers.

public abstract class Question
{
    public Question(string questionText)
    {
        this.QuestionText = questionText;
    }

    public string QuestionText { get; set; }
}

// Non-generic
public class Response
{
    public object Value { get; }
}

// Generic
public class Response<T> : Response
{
    public T Value { get; set; }
}

public class MathProblemQuestion : Question
{
    public Response Response { get; set; }
}

public class MultipleChoiseQuestion : Question
{
    public Response Response { get; set; }

    public IEnumerable<Response> PossibleResponses;

    ...
}

public class TrueOrFalse : Question
{
    ...
}
  • 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-06T19:19:05+00:00Added an answer on June 6, 2026 at 7:19 pm

    I would personally just give them different names. It will make your life much simpler, and the code much clearer:

    public abstract class Response
    {
        public abstract object ObjectValue { get; }
    }
    
    public class Response<T> : Response
    {
        public T Value { get; set; }
    
        public override object ObjectValue { get { return Value; } }
    }
    

    Note that I’ve made the Response class abstract – it’s hard to see how it could work elegantly otherwise; if Response has its own storage for Value then presumably that could be set to a non-T value. Hopefully making this abstract won’t be a problem for you.

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

Sidebar

Related Questions

Which .NET languages have error as a keyword? I have a class named Error
Which of the following has the best performance? I have seen method two implemented
Which constitutes better object oriented design? Class User { id {get;set} } Class Office
Which of the two is correct terminology?
I am trying to understand how to use SyndicationItem to display feed which is
Which class or delegate should I sub-class to dig deeper into the call-stack of
Which do you think the best way to pass data between the two sides
I have a text area in my form which accepts all possible characters from
Which ORM supports sql like batch insert/update/delete: var user=new UserInfoFields(); var update=user.Update().Set ( user.Field1=1,
Which class design is better and why? public class User { public String UserName;

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.