An Interface is a collection of data members and member functions but it does not implement them. The methods defined in an Interface do not have implementation, they only specify the parameters that they will take and the types of values they will return. An Interface is always implemented in a Class.
An Interface can have same access modifier as a class, such as Public and Private.
Interfaces are introduced to provide the feature of multiple inheritance to classes. Multiple Inheritance is the feature of
object oriented programming which allows a class to inherit from multiple classes.
Points to Remember :-
Below we have created a Interface and named it as IMyinterfaceName and inside the Interface we define a method named as myfirstMethod.
Interface IMyinterfaceName
{
Void myfirstMethod();
}
Difference between Interface and Abstract Classes in C# ? Describe it in details.
There are few difference between Interface and Abstract Classes , they are listed below.
When do you choose Interface over an Abstract Class or vice versa ?.
If you have implementation that will be the same for all the derived classes , then it is better to go for an abstract Class instead of an Interface. so you can share implementation for all derived classes in one central place, and avoid code duplication in the derived classes. rather than you have an interface you can move your implementation to any class that implements the interface.
About the Author
Sudheer Singh Chouhan is a Software Engineer having Expertise in Development Design and Architecting the
applications , Project Management , Designing Large Scale Databases in SQL Server since last 17 Years.
Skill Sets :- Microsoft .NET technologies like ASP.Net Core, Web API, LINQ, Web Forms, WinForms, SQL Server,
EntityFramework, Design Patterns, Solid Principles, Microservices, AWS Cloud.