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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:34:16+00:00 2026-05-28T07:34:16+00:00

Given two interfaces: interface I1 { int Foo(); } interface I2 { void Foo();

  • 0

Given two interfaces:

interface I1 {
    int Foo();
}

interface I2 {
    void Foo();
}

And a class:

class Test : I1, I2 {
    int I1.Foo() {
        Console.WriteLine("I1.Foo");
        return default(int);
    }

    public void Foo() {
        Console.WriteLine("I2.Foo");
    }
}

How can I extend the interface I2 with I1 by keeping the methods named Foo?

I tried the following code but it doesn’t compile:

interface I1 {
    int Foo();
}

interface I2 : I1 {
    void I2.Foo();
} 

class Test : I2 { /* same 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-28T07:34:17+00:00Added an answer on May 28, 2026 at 7:34 am

    It is unclear in the example what explicitly declaring I2.Foo() in the interface itself would accomplish if it were permitted. The specification (s. 13.4.1) allows the struct or class implementing an interface to declare an explicit member implementation. (Interfaces cannot declare any implementation, explicit or otherwise).

    Thus, suppose we have defined:

    interface IFoo
    {
        void Bar();
    }
    
    interface IBaz : IFoo
    {
        new void Bar();
    }
    
    interface IQux : IBaz { }
    
    class A : IQux // equivalent to class A : IQux, IBaz, IFoo (spec sec. 13.4.6)
    {
        void IFoo.Bar()
        {
            Console.WriteLine("IFoo.Bar");
        }
    
        void IBaz.Bar()
        {
            Console.WriteLine("IBaz.Bar");
        }
    
        public void Bar()
        {
            Console.WriteLine("A.Bar");
        }
    
        // Not allowed: void IQux.Bar() {...}
        // Since "The fully-qualified name of the interface member
        // must reference the interface in which the member
        // was declared" (s. 13.4.1)
    }
    

    Then the following driver shows the effect of the explicit interface method implementation.

    public static void Main()
    {
        A a = new A();
        a.Bar(); // prints A.Bar
        (a as IFoo).Bar(); // prints IFoo.Bar
        (a as IBaz).Bar(); // prints IBaz.Bar
        (a as IQux).Bar(); // prints IBaz.Bar
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two interfaces: interface A { void foo(); } interface B { void
In C#, I can implement a generic interface twice on one class, using two
I have the following two interfaces: public interface ParsedFile<K, V extends FileEntry>{...} And public
Suppose I have this class hierarchy: class A { public: virtual void foo(Base *b)
Given two interface references obtained from different sources. Is there a programmatic way to
Given two colors and n steps, how can one calculate n colors including the
Class A can implement multiple interfaces. What I do not understand is what happens
For School I have been given a class interface to define my own array
Given the following template: template <typename T> class wrapper : public T {}; What
In C++ methods can have optional arguments, like this: void myFunction (int arg1, int

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.