0
C# Interface confusion
What is real use of interfaces , please do not use Google to explain this because I can also do the same, I need some realtime explained
2 Antworten
+ 3
An interface is one of the tools to implement polymorphism in object-oriented programming.
An interface defines some behavior on the high level, that the actual class must follow and implement.
For example there is the IList interface that describes a data structure, which has indexed elements, that can be added and removed.
https://docs.microsoft.com/en-us/dotnet/api/system.collections.ilist?view=netcore-3.1
You can use this template, meaning you can implement this interface, to create your own data structure from scratch, which follows all the rules dictated by the interface's "contract".
Then any developer who will use your CustomList class, doesn't need to care how the class does its job, because it is ensured that it will have all the methods available that you expect from an IList.