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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:21:53+00:00 2026-05-14T00:21:53+00:00

In the .net framework, there’s a generic IEnumerable<T> interface which inherits from the not-generic

  • 0

In the .net framework, there’s a generic IEnumerable<T> interface which inherits from the not-generic IEnumerable, and they both have a GetEnumerator() method. The only differents between these two GetEnumerator() is the return type.
Now I have a similar design, but when I compile the code, the compiler said:

MyInterface<T>.GetItem()‘ hides inherited member ‘MyInterface.GetItem()‘. Use the new keyword if hiding was intended.

The MyInterface<T>.GetItem() returns a concrete type T, while MyInterface.GetItem() returns type System.Object.

So I think if the BCL team guys compile the .net framework, they will get the same warning.

I think having compiler warnings is not good, what do you think? And how can I solve this problem? I mean I want to get the concrete type T when calling the MyInterface<T>.GetItem() not just a instance of type System.Object.

Thanks in advance! 🙂

Supplement:
I’m saying the interfaces theirselves: IMyInterface inherits from IMyInterface, and they both have the GetItem() method (the IMyInterface.GetItem() returns type T, while IMyInterface.GetItem() returns type System.Object). The problem is that, if our code only have these two interfaces, that is, no derived concrete classes, we will encounter the compiler warning after compile the source code.

  • 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-14T00:21:54+00:00Added an answer on May 14, 2026 at 12:21 am

    They don’t because they compile one version as an Explicit Interface Method Implementation. It looks like this:

    public class SomeClassThatIsIEnumerable<T> : IEnumerable<T>
    {
        public IEnumerator<T> GetEnumerator()
        {
           // return enumerator.
        }
    
        IEnumerator IEnumerable.GetEnumerator()
        {
            return ((IEnumerable<T>)this).GetEnumerator();
        }
    }
    

    What this type of construct does is make the first GetEnumerator method become the default method, while the other GetEnumerator method is only accessible if the caller first casts SomeClassThatIsIEnumerable to the type IEnumerator, so it avoids the problem.

    Edit: based on the supplement above, you would want to use the new keyword:

    public interface IMyInterface
    {
       object GetObject();
    }
    
    public interface IMyInterface<T> : IMyInterface
    {
       new T GetObject();
    }
    
    // implementation:
    
    public class MyClass : IMyInterface<string>
    {
        public string GetObject() 
        {
            return "howdy!";
        }
    
        object IMyInterface.GetObject()
        {
            return GetObject();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 320k
  • Answers 320k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The same origin policy is a browser thing, not a… May 14, 2026 at 12:22 am
  • Editorial Team
    Editorial Team added an answer Matt's version is much cleaner. I recommend everyone to use… May 14, 2026 at 12:22 am
  • Editorial Team
    Editorial Team added an answer If I just say mvn jetty:run-war it fails. That's not… May 14, 2026 at 12:22 am

Related Questions

I know that in the .NET framework there are a handful of alternative third-party
Is there a way in the .NET framework to validate that a process has
Is there any class in the .NET framework that can read/write standard .ini files:
Is there a class in the .NET framework that I can used to catch
I'm curious if there is support in the .NET Framework to map .NET data

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.