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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:18:45+00:00 2026-05-17T22:18:45+00:00

I have one generic interface in c#, and almost always I use it with

  • 0

I have one generic interface in c#, and almost always I use it with one of the types. I want to create a non-generic interface for that type and use it.

Let’s say, I’ve the following code:

public interface IMyGenericList<out T> where T : IItem
{
    IEnumerable<T> GetList();
}

public class MyList<T> : IMyGenericList<T> where T : IItem
{
    public IEnumerable<T> GetList()
    {
        return null;
    }
}

it works well. Most times I need IMyGenericList<IItem>, so i try the following:

public interface IMyItemsList : IMyGenericList<IItem>
{
}

but I can’t make MyList implement IMyItemsList for some reason. The following code returns an error

public class MyList<T> : IMyItemsList, IMyGenericList<T> where T : IItem
{
    public IEnumerable<T> GetList()
    {
        return null;
    }
}

saying that IEnumerable<IItem> is not implemented.

Why is it so/what can I do with this?
Thanks.

Ok, thanks to your answers I figured out it’s impossible to do it exactly as I wanted initially. I will post another question on why this is impossible 🙂
Here it is: One function implementing Generic and non-generic interface

  • 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-17T22:18:46+00:00Added an answer on May 17, 2026 at 10:18 pm

    You specific example wouldn’t work, as your class:

    public class MyList<T> : IMyItemsList, IMyGenericList<T> where T : IItem
    {
      public IEnumerable<T> GetList()
      {
        return null;
      }
    }
    

    is trying to implement both a IEnumerable<IItem> GetList() and an IEnumerable<T> GetList(), which are two different things. This first is explicitly an enumerable of IItem (as required by your IMyItemsList interface), and the second is an enumerable of T.

    In this scenario T is of type IItem but is not explicitly IItem. Therefore at compile time, the IEnumerable<IItem> GetList() is not IEnumerable<T> GetList() so the compiler will correctly throw an error telling you that IEnumerable<IItem> GetList() is not implemented.

    The other problem you will run into, is what happens when somebody does:

    var list = new MyList<IItem>();
    

    The compiler will try and create an a concrete implementation of MyList<IItem> which will have two definitions of IEnumerable<IItem> GetList().

    I would reconsider your design to evaluate a singular IEnumerable<T> GetList().

    Also, and just picky on my part: “enumerable” != “list” 😛

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

Sidebar

Related Questions

Here's the situation: We have some generic graphics code that we use for one
I have one field that I need to sum lets say named items However
I have two interfaces, a generic and a non-generic that have an inheritence hierarchy:
Lets say I have a class, which implements a generic interface public interface IItem
I have an interface which takes a generic type interface IIFace<T> Then i have
I have one thread that writes results into a Queue. In another thread (GUI),
I have one hibernate sequence, that generates all sequence-numbers in my app. When I
I have one text input and one button (see below). How can I use
I have an interface ISerializeDeserialize defined and some classes inheriting the generic interface. I
I have an interface parametrized on a type which extends a parametrized type, and

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.