Home > DeveloperSection > Interviews > What is a basic concept of Interface

Posted on    September-15-2016 1:39 AM

 C# C# 
Ratings:
 1 Answer(s)
  79  View(s)
Rate this:

Jonas Stuart
Jonas Stuart

Total Post:11

Points:55
Posted on    September-15-2016 1:39 AM

Interface is used in the C# for declaring the function etc, which can be implement, in the various  class. It is similar to the base class which can be inherit into the derived but it is multilayered and class inherit concept is single layer hence it is more accessible.

For Example-

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace ConsoleApplication11
{
    interface Interface1
    {
        void SampleMethod();
    }
    interface Interface2
    {
        void SampleMethod2();
    }
 
    class interfacedemo : Interface1, Interface2
    {
 
        public void SampleMethod()
        {
            Console.WriteLine("Sample Method");
        }
        public void SampleMethod2()
        {
            Console.WriteLine("SampleMethod2");
        }
        static void Main()
        {
            interfacedemo obj = new interfacedemo();
            obj.SampleMethod();
            obj.SampleMethod2();
            Console.ReadLine();
        }
    }
}

Don't want to miss updates? Please click the below button!

Follow MindStick