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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:34:46+00:00 2026-05-29T09:34:46+00:00

I want to implement a generic class AppContextItem with the generic Interface IAppcontextItem. As

  • 0

I want to implement a generic class AppContextItem with the generic Interface IAppcontextItem. As I want to store multiple AppContextItems inside of a List without knowing the exact type (and also I want to be able to mix multiple typed AppContextItems inside the list). I created another non-generic Interface IAppContextItem. The generic implementation of IAppContextItem should hide the non-generic fields but it somehow doesn’t, because I get an compile error that tells me I need to implement Element with return type object. Is it impossible to do what I want or did I get something wrong?

IAppcontextItem.cs

public interface IAppContextItem
{

    string Key { get; set; }

    object Element { get; set; }

}

public interface IAppContextItem<T> : IAppContextItem 
    where T : class
{
    new string Key { get; set; }
    new T Element { get; set; }
}

AppContextItem.cs

public class AppContextItem<T> : IAppContextItem<T> where T : class
{

    private string key = string.Empty;
    private T element;

    public string Key
    {
        get { return key; }
        set { key = value; }
    }

    public T Element
    {
        get { return element; }
        set { element = value; }
    }
  • 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-05-29T09:34:47+00:00Added an answer on May 29, 2026 at 9:34 am

    You have to implement both the T Element and object Element properties. The implementation for object Element will look like:

    object IAppContextItem.Element
    {
       get; set;
    }
    

    You can then cast it to the correct interface:

     AppContextItem<MainApp> app = new AppContextItem<MainApp>();
     IAppContextItem iapp = (IAppContextItem)app;
     object o = iapp.Element;
    

    This is called Explicit Interface Implementation.

    If you want to have a different implementation of IAppContextItem.Key and IAppContextItem<T>.Key you can use explicit interface implementation like this:

    string IAppContextItem.Key
    {
        get { return key + "A"; }
        set { key = value; }
    }
    
    string IAppContextItem<T>.Key
    {
        get { return key + "B"; }
        set { key = value; }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to implement a generic method on a generic class which would allow
I am practicing programming with generic classes. I want to implement a class for
I just finish to implement a generic skip list in C++ an I want
I am very new to Scala. I want to implement a generic matrix class
I am trying to have a List of classes that implement a generic class
I want to implement a generic, thread save class which takes the RessourceId of
I have a generic list class that implements a particular interface. The list items
I want to implement a generic Observer Pattern for user controls. What is the
How would you implement a capacity-limited, generic MruList in C# or Java? I want
I want to have a generic object that implements an interface. I mean if

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.