Is there a way to do this?

Suppose we have an interface I with one method, call it method(). We have class A that implements the interface, and a class B that derive from A. Both classes decide to hidde the implementation of the interface. How can a method of class B, lets call it ShowUpperMethod(), can call method() in A

PD> Here is the code to help understand... :) thx.

namespace ExplicitImplementation
{
public interface I
{
void method ();
}

public class A : I
{
void I.method ()
{
Console.WriteLine ("Im class A implementing interface...");
}
}

public class B : A, I
{
public void ShowUpperMethod ()
{
// I want to call the method() in the upper class.
}

void I.method ()
{
Console.WriteLine ("Im class B implementing interface...");
}
}
}

Comments

  • This code may help you. To call an upper method you can use the key word "base".


    namespace ConsoleApplication1
    {
    class Program
    {

    public static void Main(string[] args)
    {
    A expA = new A();
    B expB = new B();

    expA.method();
    expB.ShowUpperMethod();
    expB.method();
    Console.ReadKey();

    }
    }

    public interface I
    {
    void method();
    }

    public class A : I
    {
    public void method()
    {
    Console.WriteLine("Im class A implementing interface...");
    }
    }

    public class B : A, I
    {
    public void ShowUpperMethod()
    {
    base.method();
    }

    public void method()
    {
    Console.WriteLine("Im class B implementing interface...");
    }
    }
    }
  • This post has been deleted.
  • Ok, I understand that part. However, I wanted the methods to be hiden in both clases. Like I showed before:

    void I.method ()

    See the example that I had there.

    Any clue? I mean I haven't figure out.
  • This post has been deleted.
  • This post has been deleted.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories