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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:01:06+00:00 2026-06-11T05:01:06+00:00

I accidentally came across this in C# 4.0 when I was trying to implement

  • 0

I accidentally came across this in C# 4.0 when I was trying to implement a nested interface with an abstract class:

public class A
{
    public interface InnerInterface
    {
        void Method();
    }
}

public abstract class B : A.InnerInterface
{
    public abstract void A.InnerInterface.Method();
}

public class C : B
{
    public override void A.InnerInterface.Method()
    {
        System.Console.WriteLine("C::A.InnerInterface.Method()");
    }
}

Unfortunately the above code fails to compile, with the following errors:

error CS0106: The modifier ‘abstract’ is not valid for this item

error CS0106: The modifier ‘public’ is not valid for this item

error CS0106: The modifier ‘override’ is not valid for this item

error CS0106: The modifier ‘public’ is not valid for this item

However if the interface is instead a non-nested interface, like this:

public interface SomeInterface
{
    void Method();
}


public abstract class B : SomeInterface
{
    public abstract void Method();
}

public class C : B
{
    public override void Method()
    {
        System.Console.WriteLine("C::Method()");
    }
}

It compiles OK.

Why the compiler error in the first case? Am I missing something here? Or is it not allowed to implement a nested interface with an abstract class?

  • 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-11T05:01:07+00:00Added an answer on June 11, 2026 at 5:01 am

    The problem isn’t with the nesting – it’s with explicit interface implementation. If you change your “working” example to use:

    public abstract void SomeInterface.Method()
    

    you’ll see the same problem. You should be able to use implicit interface implementation with a nested interface easily:

    public abstract class B : A.InnerInterface
    {
        public abstract void Method();
    }
    
    public class C : B
    {
        public override void Method()
        {
            System.Console.WriteLine("C::A.InnerInterface.Method()");
        }
    }
    

    … and if you want to use explicit interface implementation, it should work in the same way for a nested interface as a non-nested one. But you don’t write public on explicit interface implementations, and they can’t be abstract either (IIRC).

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

Sidebar

Related Questions

I accidentally came across this weird but valid syntax i=3 print i+++i #outputs 6
I came across this code accidentally: #include<stdio.h> int main() { int i; int array[3];
I came across this issue accidentally when I was going over inheritance and up/down
I accidentally came across $(undefined) in a statement below, where params is an object:
Today I came across a problem where someone had accidentally committed a proj.user file
Accidentally I found this post about a new feature in ASP.NET 4.0: Expressions enclosed
I accidentally closed the Properties tab in Eclipse. I need this to do some
I accidentally added my project to a folder. How can I undo this? Here's
I accidentally deleted the private and public key pair of my certificate, but I
I accidentally pushed a commit to GitHub. Is it possible to remove this commit?

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.