You must Sign In to post a response.
  • Category: ASP.NET

    What are interfaces, what is the use them in project?

    Dear Friends
    I would like implement project with c# interface , but i never try interface in my previous project..

    can any one suggest me to how to write the code using interface and how to call that interface in front end..
  • #764604
    Hi navaneethakrishnan.

    Interface is nothing but a template or class. Which contains the abstract methods which are public abstract by default with in the interface. The implementation of abstract methods are provided in the derived classes.
    to understand the use of interfaces you must know about abstract classes.
    Multiple inheritance is achieved using the interfaces.

    As per your question we are not going to call interface, we call the interface methods by creating the reference not object. As we can't create object for an interface.

    Interface contain only abstract methods, which are public abstract by default.
    1.Interface can implement another interface but cannot implement abstract class.
    2.Object cannot be created for interface, reference can be created.

    public interface ISample:IMysample
    void mymethod();
    void mymethod2();

    Refer below two links which gives you clear idea of abstract class and interface.

    Sridhar Thota.
    Editor: DNS Forum.

  • #764605
    Interface are alternative to multiple inheritance, Interfaces are declared using the interface keyword. It is similar to class declaration. Interface statements are public by default.
    see below sample
    public interface ITransactions
    // interface members
    void showTransaction();
    double getAmount();
    An interface looks like a class, but has no implementation. The only thing it contains are declarations of events, indexers, methods and/or properties. The reason interfaces only provide declarations is because they are inherited by structs and classes, that must provide an implementation for each interface member declared.
    check below links for more detail

    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #764655
    Here you go for complete details about interface:

    Asheej T K
    Microsoft MVP[ASP.NET/IIS]
    DotNetSpider MVM

  • #764660
    Hi Naveen

    Refer to the below..
    In an interface class, all methods are abstract (undefined)- there is no implementation so when we create an interface, we are creating a set of methods, properties without any implementation and it must be overridden by the implemented classes. The benefit is that it allows a class to be a part of two classes: one from inheritance hierarchy and one from the interface.

    For this,can't contain constructors and destructors.


    public interface Iget
    { void get();
    public class get : Iget
    public void get()
    { Console.WriteLine("example for interface");

    Hope this will help you

    Never lose hope..You never know what tomorrow will bring

Sign In to post your comments