Accessibility and Interface

P

Paul Bawin

Hi All,

I have some troubles with the implementation of a internal interface

If I define it like below, the method "AMethod" is visible outside the
assembly
namespace Client
{
internal interface IClient
{
void AMethod();
}
public class Class : IClient
{
public void AMethod()
{
}
}
}
If I define it like below, the method "AMethod" is hidden outside the
assembly
namespace Client
{
internal interface IClient
{
void AMethod();
}
public class Class : IClient
{
void IClient.AMethod()
{
}
}
}

But in the two models, I implement the interface of IClient but the result
is different

Anybody can help me to explain the difference

Sincerely,
Polo
 
C

Chris Taylor

Hi,

What you implement an interface member using it's fully qualified name,
this is refered to as explicit interface member implementation. Members
implemented are not publically available through an instance of class
that implements the interface member, however if you cast the object to
the interface you can access that member through the interface
reference. In your case this last option will not work because you have
marked the interface internal so you will not be able to do the cast
outside of that assembly.

For further details, see section 13.4.1 of the C# language
specification.

Hope this helps

Chris Taylor
http://www.xanga.com/home.aspx?user=taylorza
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top