Article
    C#
    ADO.Net
    .NET
    ASP.Net & Web Forms
    Custom Controls
    Web Development
    Exception Handling
    XML
    Database
    Security in .Net
    Testing
    Web Services
    Windows Services
    Windows Controls
    WCF
    AJAX
    WPF
    XAML
    Reporting
    Setup
    VB.Net
    LINQ
    JQuery
    SilverLight
    JavaScript
    HTML5
    Crystal Report
    Cloud Computing
    Share Point
    Visual C++
    MVC
    Android
    PHP
    Java
    HTML
    WordPress
    Joomla
    Products
    Drupal
    Windows Phone
    JSON
    LightSwitch
    iPhone/iPad
    Ruby on Rails
    IIS 7
    Windows 8
    CSS/CSS3
    Excel
    MS Access
    Shortcut Keys
    Visual SourceSafe
    Team Foundation Server
    API(s)
    Sencha-Touch
Follow Us
Follow _MindStick_ on Twitter View MindStick Software's LinkedIn profile View MindStick Software's Facebook profile
Top Contributor
Advertisement
Advertise with Us
Mindstick
Article Article  Forum Forum  Blog Blog  Quiz Quiz  Beginner Beginner  Careers Careers  Contact Contact  Login Login  
Home | Product | Services | About Us | Interview | DeveloperSection | Submit an Article | Submit Blog

Home >> .NET >> Interfaces
Interfaces
Interfaces


by Haider M Rizvi on 7/15/2010 5:25:40 PM

Views: 1526       Comments: 0

Interfaces in C#.Net

An interface looks like a class, but has no implementation. The only thing it contains is definitions of events, indexers, methods and/or properties. The reason interfaces only provide definitions is because they are inherited by classes and structs, which must provide an implementation for each interface member defined.

Example

//defining first interface

    interface Ifirst

    {

        void sum(int a, int b);

    }

 

//defining second interface which inherits first interface

    interface Isecond:Ifirst

    {

        void sub(int a, int b);

    }

 

//defining class which inherits second interface

 

    class newClass : Isecond

    {

//implementing interface defined methods

        public void sum(int a, int b)

        {

            MessageBox.Show("Sum is: " + (a + b).ToString());

        }

        public void sub(int a, int b)

        {

            MessageBox.Show("Difference is: " + (a - b).ToString());

        }

    }

Demonstrating use

//creating instance of class

newClass c = new newClass();

private void btnSum_Click(object sender, EventArgs e)

        {      

//calling sum() of Ifirst interface    

c.sum(Convert.ToInt32(txtNum1.Text), Convert.ToInt32(txtNum2.Text));

        }

 

 

 

 

        private void btnSub_Click(object sender, EventArgs e)

        {

//calling sub() of Isecond interface

c.sub(Convert.ToInt32(txtNum1.Text), Convert.ToInt32(txtNum2.Text));

        }

Report Abuse Form
Reason:    
 

Title :
Comment :
Text ColorBackground Color
BoldItalicUnderline
LeftCenterRightJustify
Ordered ListBulleted List
IndentOutdent
Horizontal Rule
SubscriptSuperscript
HyperlinkImage
Design ModeDesign
View HtmlHtml
     
 
Latest Article by Haider M RizviRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Latest BlogsRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Top Viewed ArticlesRSS Feed
    
    
    
    
    
    
    
    
    
    
Top Viewed BlogsRSS Feed
    
    
    
    
    
    
    
    
    
    
Latest Interview QuestionsRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Total Online Users: 2729
Advertisement
MindStick Cleaner
Advertise with Us
  
Copyright © 2009 - 2013MindStick. All Rights Reserved.