public interface IValidator
{
void ValidateX(ArrayList al);
void ValidateY(ArrayList al);
}
public class Employee : IValidator
{
public void ValidateX(ArrayList al)
{
}
void IValidator.ValidateY(ArrayList al)
{
}
}
public class A
{
public A()
{
Employee e = new Employee();
}
public void Test1()
{
e.ValidateX( New ArrayList() ); // can call this
e.ValidateY( New ArrayList() ); //CANNOT CALL
}
}
In the class "A" why i was able to call ValidateX() and not ValidateY()?
whats the difference with calling a interface method as :
public void ValidateX(ArrayList al)
{
}
and
void IValidator.ValidateY(ArrayList al)
{
}
?
cheers

1 answers
In the Employee class, the ValidateX method is implemented normally.
However, ValidateY is implemented using 'explicit interface implementation'. This means that you can only call ValidateY via an IValidator reference - you can't call it via an Employee reference.
To call it, change this line:
e.ValidateY( new ArrayList() ); // notice New should be lower case
with:
IValidator iv = e;
iv.ValidateY( new ArrayList() );
You can also knock this into a single line with:
((IValidator)e).ValidateY( new ArrayList() );
answered 10 months ago by:
12813
you can also not implement it explicitly.
answered 10 months ago by:
1754
This post was imported from csharpfriends, if you have a similiar question please ask it again.
All previous members have been migrated, hope you enjoy the new platform!