Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I studied that Interface is used for achieving the concept of multiple inheritance. Can anyone say what is the main use of interface in C# and Java. Where its used mostly?.
Posted

An interface is used to define a contract for a class or struct to implement. There are several uses of interfaces. As it is said in the question interfaces are used in C# as an alternative to multiple inheritance. Interfaces with extension methods are used extensively in LINQ. Lot of answers were given on this topic here
Purpose of Interfaces[^]
I think it may be useful to you.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 16-Apr-12 22:34pm    
My 5, mostly for mentioning struct. Too many developers, being asked if an interface can be implemented by a structure, would answer "no". I also was under the influence of this myth for a long time, until I finally checked it up. With multiple inheritance for interfaces, it brings a new quality to polymorphism: the set of element types can be abstracted from the nature of types (reference vs value types), and the type do not have to belong to the hierarchy of a compile-time element type.
--SA
VJ Reddy 16-Apr-12 23:38pm    
Thank you very much, SA, for appreciation and additional points.
 
Share this answer
 
I guess Interfaces are mostly used in C# to create a blue print of a class, like what members class would have etc.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900