s

C# Interface edit button Edit

author
Rakesh Kumar Sutar | calendar 20 January 2021 | 2456

Introduction

Interfaces define properties, methods, and events, which are the members of the interface. Interfaces contain only the declaration of the members. It is the responsibility of the deriving class to define the members. It often helps in providing a standard structure that the deriving classes would follow. Abstract classes to some extent serve the same purpose, however, they are mostly used when only few methods are to be declared by the base class and the deriving class implements the functionalities.

Example

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hello_World
{

    interface IAnimal
    {
        void animalColour(); 
    }

    
    class Pig : IAnimal
    {
        public void animalColour()
        {

            
            Console.WriteLine("\t" "The pig is white and black");
        }
    }
    class program
    {
        static void Main(String[] args)
        {

            Pig myPig = new Pig();
            Console.WriteLine();
            myPig.animalColour();
            Console.ReadLine();

        }

    }
    
      
    }

    



Output