Response to: why i get compilation error when i use explict interface implemntion
Revision 1
Solution is:
interface IXYZ
{
string Name { set; }
}
class Logger : IXYZ
{
string IXYZ.Name string IXYZ.Name { set { ((IXYZ) this).Name = value; }}
private void GenerateAutoName()
{
((IXYZ) this).Name = "Name";
}
}
1)First, if it is explicit interface implementation, then you have to cast that member while setting it, where you were getting compilation error.
((IXYZ)this).Name is correct.
2)Then the next problem is, you should have set property implemented, can not keep it as set; unless class is abstract, so make it as
set{}.
3) Interface properies are by default public, remove explicit
public modifier of Name.
4) You can not have get; in your class if it is not declared in interface.
5) You will be able to access that property with reference of IXYZ and not with Logger class reference.
Hope it helps. :)
Posted 1-Feb-13 20:11pm
by
Kishor Deshpande.