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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:49:32+00:00 2026-05-14T14:49:32+00:00

I am getting this error while creating a public method on a class for

  • 0

I am getting this error while creating a public method on a class for explicitly implementing the interface. I have a workaround: by removing the explicit implementation of PrintName method. But I am surprised why I am getting this error.

Can anyone explain the error?

Code for Library:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Test.Lib1
{

    public class Customer : i1 
    {
        public string i1.PrintName() //Error Here...
        {
            return this.GetType().Name + " called from interface i1";
        }
    }

    public interface i1
    {
        string PrintName();
    }

    interface i2
    {
        string PrintName();
    }
}

Code for Console Test Application:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Test.Lib1;

namespace ca1.Test
{
    class Program
    {
        static void Main(string[] args)
        {
            Customer customer = new Customer();
            Console.WriteLine(customer.PrintName());

            //i1 i1o = new Customer();
            //Console.WriteLine(i1o.printname());

            //i2 i2o = new Customer();
            //Console.WriteLine(i2o.printname());

        }
    }
}
  • 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-14T14:49:32+00:00Added an answer on May 14, 2026 at 2:49 pm

    When using explicit implementation of an interface, the members are forced to something more restricted than private in the class itself. And when the access modifier is forced, you may not add one.

    Likewise, in the interface itself, all members are public. If you try to add a modifier inside an interface you will get a similar error.

    Why are explicit members (very) private? Consider:

    interface I1 { void M(); }
    interface I2 { void M(); }
    
    class C : I1, I2
    {
        void I1.M() { ... }
        void I2.M() { ... }
    }
    
    C c = new C();
    c.M();         // Error, otherwise: which one?
    (c as I1).M(); // Ok, no ambiguity. 
    

    If those methods were public, you would have a name-clash that cannot be resolved by the normal overload rules.

    For the same reason you cannot even call M() from inside a class C member. You will have to cast this to a specific interface first to avoid the same ambiguity.

    class C : I1, I2
    {
       ...
       void X() 
       {  
         M();             // error, which one? 
         ((I1)this).M();  // OK 
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting this error message while creating table with one of the column
I´m getting this error while trying to commit to a svn repository: svn: MKACTIVITY
I am getting this error While running this LoadError: Expected /home/user/Desktop/Tripurari/myapp/app/models/host.rb to define Host##
I am getting this error while i am trying to upload a database that
I keep getting this error while trying to modify some tables. Here's my code:
in the aspx page i am getting this error while binding dropdown list Unable
I'm new to AS3 and I'm getting this error while trying to implement OO
I am using zendgdata library for google calendar. I am getting this error while
I am getting this weird error while running cucumber test: ERROR Mongo::OperationFailure: Database command
I'm Getting this error in my development log while uploadify is uploading the file

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.