INTERFACE IN C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ConsoleApplication4;
namespace ConsoleApplication4
{
interface ICustomer1
{
void print1();
}
interface ICustomer2 : ICustomer1
{
void print2();
}
public class Customer : ICustomer2
{
public void print1()
{
Console.WriteLine(“INTERFACE METHOD IMPELMENTED”);
Console.ReadLine();
}
public void print2()
{
Console.WriteLine(“INTERFACE I2METHOD IS IMPLEMENTED TOO”);
Console.ReadLine();
}
}
}
public class Program
{
static void Main()
{
Customer C1 = new Customer();
C1.print1();
C1.print2();
Console.ReadLine();
}
}
===================================================================
EXPLICIT INTERFACE IMPLEMENTATION
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ConsoleApplication4;
namespace ConsoleApplication4
{
interface I1
{
void INTERFACEMETHOD();
}
interface I2 : I1
{
void INTERFACEMETHOD();
}
public class Program : I1,I2
{
// PUBLIC VOID INTERFACEMETHOD() DEFAULT INTERFACE METHOD
void I1.INTERFACEMETHOD()
{
Console.WriteLine(“INTERFACE I1”);
Console.ReadLine();
}
void I2.INTERFACEMETHOD()
{
Console.WriteLine(“INTERFACE I2”);
Console.ReadLine();
}
static void Main()
{
Program P = new Program();
// P.INTERFACEMETHOD(); DEFAULT INTERFACE CALLING
((I1)P).INTERFACEMETHOD();
((I2)P).INTERFACEMETHOD(); // EXPLICIT INTERFACE METHOD CALLING
Console.ReadLine();
}
}
}