Tuesday, July 28, 2009

Could u explain the EII (explicit interface implemention )method in C#.net?

n also i want 2 c if its the only way of defining interface methodes?

Could u explain the EII (explicit interface implemention )method in C#.net?
Hi sarah


If a class implements two interfaces that contain a member with the same signature, then implementing that member on the class will cause both interfaces to use that member as their implementation. For example:





C# Copy Codeinterface IControl


{


void Paint();


}


interface ISurface


{


void Paint();


}


class SampleClass : IControl, ISurface


{


// Both ISurface.Paint and IControl.Paint call this method.


public void Paint()


{


}


}








If the two interface members do not perform the same function, however, this can lead to an incorrect implementation of one or both of the interfaces. It is possible to implement an interface member explicitly—creating a class member that is only called through the interface, and is specific to that interface. This is accomplished by naming the class member with the name of the interface and a period. For example:


No comments:

Post a Comment