Blog
    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
    APIs
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
Report Abuse Form
Reason:    
 

Home >> C# >> Interface in C#.Net
Interface in C#.Net

An interface contains only the signatures of methods, delegates or events. An interface looks like a class, but has no implementation. The only thing it contains is declarations of events, indexers, methods and/or properties. Interfaces in C # provide a way to achieve runtime polymorphism.
Views: 695     Comments: 0
by AVADHESH PATEL on 7/10/2012

Interface in C#.Net

An interface contains only the signatures of methods, delegates or events. An interface looks like a class, but has no implementation. The only thing it contains is declarations of events, indexers, methods and/or properties. Interfaces in C # provide a way to achieve runtime polymorphism.

Why Use Interfaces?

To allows a class to inherit multiple behaviors from multiple interfaces.

To avoid name ambiguity between the methods of the different classes as was in the use of multiple inheritances in C++.

To combine two or more interfaces such that a class need only implement the combined result. The example code for this is provided as a source file to be downloaded.

To allows Name hiding: Name hiding is the ability to hide an inherited member name from any code outside the derived class.

Defining an Interface

interface IMyInterface
{
void MethodToImplement();
}

Implementation of Interface

class InterfaceImplementer : IMyInterface
{
static void Main()
{
InterfaceImplementer iImp =
new InterfaceImplementer();
iImp.MethodToImplement();
}

public
void MethodToImplement()
{
Console.WriteLine("MethodToImplement() called.");
}
}

Compile example:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace @interface

{

    interface IMyInterface

    {

        void MethodToImplement();

    }

       class InterfaceImplementer : IMyInterface

    {

        static void Main()

        {

            InterfaceImplementer iImp = new InterfaceImplementer();

            iImp.MethodToImplement();

            Console.ReadLine();

        }

        public void MethodToImplement()

        {

            Console.WriteLine("MethodToImplement() called.");

        }

    }

}

Output:

MethodToImplement() called.

Title :  
Comment :
Text ColorBackground Color
BoldItalicUnderline
LeftCenterRightJustify
Ordered ListBulleted List
IndentOutdent
Horizontal Rule
SubscriptSuperscript
HyperlinkImage
Design ModeDesign
View HtmlHtml
       
 
Report Abuse Form
Reason:    
 
Latest ArticleRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Latest Blogs by AVADHESH PATELRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Top Viewed ArticlesRSS Feed
    
    
    
    
    
    
    
    
    
    
Top Viewed BlogsRSS Feed
    
    
    
    
    
    
    
    
    
    
Latest Interview QuestionsRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Total Online Users: 7307
  
Copyright © 2009 - 2013MindStick. All Rights Reserved.