Unimatrix_001
asked on
Implementing interface & redefining a method.
Morning,
Obviously the above code is very wrong as Calculate is defined twice within MyClass, but is there a way I can state that one of the Calculate methods only be accessible through MyInterface and the other Calculate method available through MyClass. So:
Any tricks to make this possible without having two different named methods?
Thank you,
Uni
public interface MyInterface{
int Calculate();
}
public class MyClass:MyInterface{
int Calculate(){return 0;}
int Calculate(){return 1;}
}
Obviously the above code is very wrong as Calculate is defined twice within MyClass, but is there a way I can state that one of the Calculate methods only be accessible through MyInterface and the other Calculate method available through MyClass. So:
void Test(){
MyClass a=new MyClass();
a.Calculate(); //Returns 0
MyInterface b=(MyInterface)a;
b.Calculate(); //Returns 1
}
Any tricks to make this possible without having two different named methods?
Thank you,
Uni
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Excellent, thank you very much. :)
ASKER
Open in new window
That should suffice, yes?
Thanks,
Uni