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

if a base class has a number of overloaded constructors, and an inheriting class has a number of overloaded constructors; can you enforce a call from an inherited constructor to a specific base constructor?

502


What are the collection types can be used in c#?

452


Can a class have multiple constructors c#?

476


Where do we use static class in c#?

466


Why do we need indexer in c#?

517






Is for loop faster than foreach?

505


How do I automate my desktop application?

475


Are arrays value types or reference types?

517


List the different stages of a thread?

463


write code for inserting and updating recoards in sql server database using connected architecture & records shoulds displayed in grid view ( use c# )

1904


What’s thread.sleep() in threading ?

488


What is datatable in c#?

469


What is the compiler of c#?

468


What is the difference between an application domain and a process?

463


Contrast between an interface and abstract class?

520