C# Interface confusion | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

26th Sep 2020, 8:18 AM
Kishor Agarwal
Kishor Agarwal - avatar
1 Answer
+ 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.
26th Sep 2020, 8:49 AM
Tibor Santa
Tibor Santa - avatar