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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:42:23+00:00 2026-06-14T02:42:23+00:00

This is what I want my classes to look like, but this code won’t

  • 0

This is what I want my classes to look like, but this code won’t compile. How do I make it work?

public interface ISomeInterface
{
    string AMember { get; }
}
public abstract class BaseClass
{
    public abstract ISomeInterface AObject { get; }
    public abstract IEnumerable<ISomeInterface> AMethod();
}

public class DerivedClass<T> : BaseClass where T : ISomeInterface
{
    public T AObject { get; private set; }
    public IEnumerable<T> AMethod()
    {
        return null;
    }
}

Compiler errors

‘Delfin.Accountancy.DerivedClass’ does not implement inherited abstract member ‘Delfin.Accountancy.BaseClass.AObject.get’

‘Delfin.Accountancy.DerivedClass’ does not implement inherited abstract member ‘Delfin.Accountancy.BaseClass.AMethod()’

Running on c# 5.0.

Notes

I’ve tried most obvious implementations, but any of them allow me to implement the base class and expose the strongly typed members at once.

I don’t want to make the base class generic, because I’ll create static methods on the base class, and also create extension methods that might work in every case of derived classes.

I also need the derived class to be generic, because T has more members than ISomeInterface in the real world case.

Thanks!

  • 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-14T02:42:25+00:00Added an answer on June 14, 2026 at 2:42 am

    What you are asking for is called return type covariance and C# does not support this (see this answer for more details). You have to modify your classes in some way but you haven’t indicated what is acceptable. Here is a way that does not change the public API, but changes the abstract methods to protected methods.

    public interface ISomeInterface
    {
        string AMember { get; }
    }
    
    public abstract class BaseClass
    {
        public ISomeInterface AObject { get { return GetAObjectImpl(); } }     
        public IEnumerable<ISomeInterface> AMethod() { return AMethodImpl(); }
    
        protected abstract ISomeInterface GetAObjectImpl();
        protected abstract IEnumerable<ISomeInterface> AMethodImpl();
    }
    
    public class DerivedClass<T> : BaseClass where T : ISomeInterface
    {
        public new T AObject { get; private set; }
    
        public new IEnumerable<T> AMethod() { return Enumerable.Empty<T>(); }
    
        protected override ISomeInterface GetAObjectImpl() 
        {
            return AObject;
        }
    
        protected override IEnumerable<ISomeInterface> AMethodImpl()
        {
            return AMethod();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want this highchart - http://jsfiddle.net/zPDca/ inside a popup. But if i decrease its
I want this for some conditional compilation code that will run in all IE's
probably a no-brainer, but please take a look at the following classes / Interfaces:
I'd like to produce a warning message when users compile code that references an
I have a bunch of Repository classes which all look a bit like the
How do I get and print a char from a user? This want do
I want this text all on one line, not spaced on two sepearate lines.
I want this function (defn ret-lowest-str-len Computes the lengths of two strings. Returns default
I want this to open on mouse over then close again when the mouse
I want this url http://www.youtube.com/watch?v=dgNgODPIO0w&feature=rec-HM-fresh+div to be transformed to: http://www.youtube.com/v/dgNgODPIO0w with php.

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.