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

    What is Interace in C#

    Interface---->> If a class contain all abstract function then it is known as an interface.Interface do not provide Implementation.They are implemented by the class and defined as seprate entities from class. An Interface represent a contract in that a class that implements an interface must implement every aspect of that interface exactly as it is defined.
    In general Interface provides control over the class. we can define feature as small groups of closly related members and can developed enhanced implementation for your interfaceswithout jeoparadizing existing code,thus minimizing compitability problems.
    It is also possible to add new feature to any time by developing adding additional interfaces and implementations.Although intrface implementations can evolve, interfaces themselves cannot be changed once published.

    An Interface can contain

    1) Abstract functions
    2)prperties
    3)Indexes
    4)Events

    An Interface can not contain

    1)Non-abstract functions
    2)constructor
    3)deconstructor
    4)Datafields

    By default interface functions are treated as public and abstract.An Interface can not be instantiated directly. Creating/deriving a new class or other interface from an Interface is compulsary/mandatory in order to provide implementation to abstract function. An interface can itself inherit from multiple interfaces.An Interface is used to implement Multiple inheritance in C#.Net.

    Program to implement Interface---

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

    namespace Interface
    {
    interface Employee
    {
    void GetEmpData();
    void DispalyEmpData();

    }
    class Manager : Employee
    {
    int EmpId;
    string EName;
    double Bonus, CA;
    public void GetEmpData()
    {
    Console.Write("Enter Managers Details :-");
    EmpId = Convert.ToInt32(Console.ReadLine());
    EName = Console.ReadLine();
    Bonus = Convert.ToDouble(Console.ReadLine());
    CA = Convert.ToDouble(Console.ReadLine());
    }
    public void DispalyEmpData()
    {
    Console.WriteLine("Manager Id is" + EmpId);
    Console.WriteLine("Manager Name is" + EName);
    Console.WriteLine("Manager Bonus is" + Bonus);
    Console.WriteLine("Manager CA is" + CA);
    }


    static void Main(string[] args)
    {

    Manager Obj1 = new Manager();
    Obj1.GetEmpData();
    Obj1.DispalyEmpData();
    Console.ReadLine();
    }
    }
    }

    output---------------------


    Enter manager Detail is-- 10
    ravi
    15000
    25000
    Manager Id is:- 10
    Manager Name is:- ravi
    Manager Bonus is:- 15000
    Manager CA is:- 25000
  • #765715
    Hi,

    This is not the place to post such type of articles, please use Articles section for posting articles in our forum.

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #765732
    This is the forum section, do you have any question or query ? or if you want to publish your something. If yes then you can write an article on such aspect and deploy it in our article section, if your article is having quality then you can applicable for reward and cash.
    You can make money from this site by posting original and quality articles that comply with Google AdSense policies.

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

  • #765754
    what do u mean by this word "Give respect to your work, Instead of trying to impress your boss." MR. Naveen ?????????


Sign In to post your comments