If an interface member method is implemented in your class without an access modifier, it is by default private.
But methods have to be either public so that they can be called through the interface, or they need to be explicit. Let us assume your interface is implemented as follows:
public interface ITest { bool IsTest(); }
To change the visibility, you can either change the interface from public to internal.
..or you can do explicit interface implementation. Explicit implementation hides the class member so it can only be accessed through the interface. All you have to do is prefix the member with the interface name, as demonstrated here:
public class Test: ITest { bool ITest.IsTest() { return true; } }
..in which case this method will be available only via the interface ITest. This way to implement the method explicitly also hides these methods from intellisense.
Please note that this requirement is only in C# where it requires that implicit interface implementations must be public. In VB.NET you do not require an explicit accessibility keyword.
No comments:
Post a Comment