Interface properties are those which are
defined in the interface and implemented in the class which implements the
interface. Interface properties do not have a definition, they just specify the
name of the property and its accessibility Read-Write, or Read-Only or
Write-Only.
The following example defines an Interface Property Name in the interface IEmployee
If the class Employee implements 2 interfaces and if both the interfaces define an Interface property with the same name “Name”, then we can implement the properties in the class by explicitly specifying the Interface name before the Property name as follows.
class Employee : IEmployee, IDepartment
The following example defines an Interface Property Name in the interface IEmployee
public interface IEmployee
{
string Name
{
get;
set;
}
}
The interfaces so defined can be
implemented in the class which implements the interface as follows.
class Employee : IEmployee
class Employee : IEmployee
{
private string strName;
//
public string Name
{
set
{
strName
= value;
}
get
{
return strName;
}
}
}
If the class Employee implements 2 interfaces and if both the interfaces define an Interface property with the same name “Name”, then we can implement the properties in the class by explicitly specifying the Interface name before the Property name as follows.
class Employee : IEmployee, IDepartment
{
private string strName;
//
public string IEmployee.Name
{
set
{
strName
= value;
}
get
{
return strName;
}
}
}
No comments:
Post a Comment