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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:44:53+00:00 2026-05-25T12:44:53+00:00

I have some classes which implement an interface as follows: class C1 : IpropTemplate

  • 0

I have some classes which implement an interface as follows:

class C1 : IpropTemplate { ... }

class C2 : IpropTemplate { ... }

:

Also there is some other class which implements another interface:

class C3 : IclassTemplate { ... }

Now, I need to specify the signature of a property into the IclassTemplate that forces the C3 to have a property which is implemented from IpropTemplate. (such as C1 or C2, etc.)

I tried this:

interface IclassTemplate
{
    ...
    IpropTemplate prop1 { get; set; }
}

class C3 : IclassTemplate
{
    ...
    public C1 prop1
    {
        get;
        set;
    }
}

In this case, compiler produces an error indicating that C3 does not implement interface member IclassTemplate.prop1 and that the C3.prop1 cannot implement IpropTemplate.prop1 because it does not have the matching return type of IpropTemplate.

What should I do?
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-05-25T12:44:54+00:00Added an answer on May 25, 2026 at 12:44 pm

    You can’t make your C3 implementation only deal in C1 – after all, you’ve guarantee that this will be valid:

    IClassTemplate c3 = new C3();
    c3.Template = new C2();
    

    If you only need to be able to read the property, it’s slightly easier:

    interface IClassTemplate
    {
        IPropTemplate Template { get; }
    }
    
    public class C3 : IClassTemplate
    {
        private readonly C1 c1 = new C1();
    
        IPropTemplate Template { get { return c1; } }
    }
    

    That lets the code in C3 know that it’s really a C1, but still implement the interface.

    Another option is to make your interface generic:

    interface IClassTemplate<T> where T : IPropTemplate
    {
        T Template { get; set; }
    }
    
    public class C3 : IClassTemplate<C1>
    {
        public C1 Template { get; set; }
    }
    

    Hopefully one of these will meet your need – if not, please give more details about what you’re really trying to achieve – the bigger picture.

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

Sidebar

Related Questions

I have some classes that all implement the same Java interface, which essentially allows
I have a package which contains an interface and several classes,some classes in this
I have some classes which extends a superclass, and in the JSP I want
I have a set of some classes which are all capable of being constructored
I have some functionality that I need in all my classes which derive from
I'm using .NET 3.5. We have some complex third-party classes which are automatically generated
I have four classes which share some arrangement of four properties. I have currently
I have some classes layed out like this class A { public virtual void
I have some classes that represent immutable objects (Quantity, Price, Probability). Is there some
I have some classes that, for one reason or another, cannot be or need

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.