C#

Moderators: None (Apply to moderate this forum)
Number of threads: 2722
Number of posts: 5749

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Is there a way to do this? Posted by Riddick on 20 Jul 2011 at 8:30 AM
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...");
}
}
}
Report
Re: Is there a way to do this? Posted by SoEnLion on 23 Sept 2011 at 3:55 AM
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...");
}
}
}
Report
Re: Is there a way to do this? Posted by Riddick on 5 Oct 2011 at 8:13 PM
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.
Report
This post has been deleted. Posted by Riddick on 5 Oct 2011 at 8:15 PM
This post has been deleted.
Report
This post has been deleted. Posted by Riddick on 5 Oct 2011 at 8:17 PM
This post has been deleted.
Report
This post has been deleted. Posted by SoEnLion on 23 Sept 2011 at 3:57 AM
This post has been deleted.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.