.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month

Home >> Articles >> C# >> Post New Resource Bookmark and Share   

 Subscribe to Articles


Posted By:Shashi Ray       Posted Date: February 25, 2009    Points: 15    Category: C#    URL: http://www.dotnetspark.com  



An interface is a declaration that a class will contain a specific set of methods with specific arguments. If a class has those methods, it is said to implement that interface. It is essentially a contract or promise that a class will contain all the methods described by that interface. Interfaces declare the signatures of public methods, but do not contain method bodies. If a class implements an interface called Xyz, you can refer to that class as if it was of type Xyz as well as by its own type. Since C# only allows a single tree of inheritance, this is the only way for a class to be a member of two or more base classes. Let's take the example of a class that provides an interface to a multiple select list like a list box or a series of check boxes.


//an interface to any group of components

//that can return zero or more selected items

//the names are returned in an Arraylist

public interface Multisel {

void clear();

ArrayList getSelected();

Panel getWindow();



When you implement the methods of an interface in concrete classes, you must declare that the class uses that interface, and, you must provide an implementation of each method in that interface as well, as we illustrate below.


/// ListSel class implements MultiSel interface

public class ListSel : Multisel {

public ListSel() {


public void clear() {


public ArrayList getSelected() {

return new ArrayList ();


public Panel getWindow() {

return new Panel ();




Shashi Ray

 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend