Solution is:
interface IXYZ
{
string Name { set; }
}
class Logger : IXYZ
{
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.
Please see below code snippet..
class Test
{
public void TestMethod()
{
IXYZ xyzRef = new Logger();
xyzRef.Name = "Hello";
Logger logRef = new Logger();
}
}
Hope it helps. :)