Understanding Interface in C#

What is an interface:

  • Interface contains definitions(only signatures) it does not contain any implementation details. it is very crispy.
  • Interface can inherit from another interface.
  • Interface can contain properties,method, events,indexers.
  • Interface can’t contain const,fields,operators,constructor and destructor.
  • Interface members are public by default.
  • Interface members can’t be static.
  • Interface can’t be instantiated directly.
  • Any number of interface can be applied on class or struct (i.e. Multiple interface can be implemented in single class or struct), but you can inherit only one class in another class.
  • Class or Struct which implement interface must provide implementation for all the implemented member.
  • Interface helps implementing multiple inheritance in C#
  • Interface helps implement inheritance in struct, since struct can’t inherit from another struct by default.

[click to continue…]