17 May 2016 Sudhanshu Ranjan 1.34k

What is Interface in C#? Explain

An interface contains only the signatures of methods, properties, events or indexers. C # provide a way to achieve runtime polymorphism. Using interfaces we can invoke functions from different classes through the same Interface reference, whereas using virtual functions we can invoke functions from different classes in the same inheritance hierarchy through the same reference.

An interface has the following properties:

•    An interface is like an abstract base class. Any class or struct that implements the interface must implement all its members.
•    An interface can't be instantiated directly. Its members are implemented by any class or struct that implements the interface.
•    Interfaces can contain events, indexers, methods, and properties.
•    Interfaces contain no implementation of methods.
•    A class or struct can implement multiple interfaces. A class can inherit a base class and also implement one or more interfaces.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TestApp
    class Demo : DEF
        public static void Main()
            System.Console.WriteLine("Hello Interfaces");
            Demo refDemo = new Demo();
            DEF refdef = refDemo;            

        void ABC.xyz()
            System.Console.WriteLine("In xyz");

        void DEF.pqr()
            System.Console.WriteLine("In pqr");


    interface ABC
        void xyz();        

    interface DEF : ABC
        void pqr();


You can share at :

About Author
Sudhanshu Kumar Ranjan | Lead Engineer at HCL Technologies | Expertise in Microsoft Technology | Author | Blogger | Programmer
Know More
Connect with him on Facebook | Google+ | LinkedIn | Twitter

Recommended Post

Leave a comment

About Dotnet Cube

It's my blog - Dotnet Cube, where you will learn and get solutions about programming, web designing and development. I started this website to share my knowledge and experience which might help someone.

You can get more details about me and my blog at About Us page.

Subscribe Newsletter

Subscribe to our monthly newsletter to get the latest industry news, Media Group updates and our current specials.

Follow On Us...

Home | About | Advertise | Copyrights | Privacy | Contact | Admin

Copyrights © 2015-2019 dotnetcube.com. All rights reserved