Y go for Interface? What is use of interface?

Answer Posted / kiran

We will go for an interface when we want to implement a
specific behaviour.

ex:
1.My class x implements IDisposable interface to handle
cleaup operation. I have to implement that behaviour by
implementing the method interface method Dispose()
explicitly in my code.

class x:IDisposable
{}
2.My class y implements IComparable interface to implement
sorting between a list of objects created of type y. Here I
have to implement CompareTo method.

Is This Answer Correct ?    3 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can you instantiate an abstract class c#?

682


What happens when thread sleep () method is called?

672


What is concrete class in c#?

652


What are value types and reference types?

766


Is char * null terminated?

711


How does dictionary work in c#?

648


What is use of hashtable in c#?

656


What is disconnected data architecture in c#?

690


Does c# support try-catch-finally blocks?

651


What is the use of system.environment class in c#.net?

717


What is the default modifier for class in c#?

698


What are logical operators in c#?

703


How long does a loop recorder procedure take?

694


List the differences between method overriding and method overloading?

682


Why do we still see so much non-oo code written in c# today?

692