Use of Interface in c#
An interface looks like a class, but has no implementation. The only thing it contains are definitions of events, indexers, methods and/or properties.The reason interfaces only provide definitions is because they are inherited by classes and structs, which must provide an implementation for each interface member defined.
example:
create an interface that contains a property LedgerName
Public interface myinterface
{
public string LedgerName
{get;}
{set;}
}
now inherite this interface into class Implement and implement that property
public class Implement:myinterface
{
string _LedgerName
public string LedgerName
{
get { return _LedgerName; }
set { _LedgerName = value; }
}
}
example:
create an interface that contains a property LedgerName
Public interface myinterface
{
public string LedgerName
{get;}
{set;}
}
now inherite this interface into class Implement and implement that property
public class Implement:myinterface
{
string _LedgerName
public string LedgerName
{
get { return _LedgerName; }
set { _LedgerName = value; }
}
}
Labels: Use of Interface in c#