C# program to demonstrate the use of an interface
Program.cs
Console.WriteLine("———————————————————————————————————————————");
Console.WriteLine("Program to demonstrate the use of interface");
Console.WriteLine("———————————————————————————————————————————");
WhiteBank wb = new WhiteBank();
GreenBank gb = new GreenBank();
gb.credit();
wb.withdraw();
Console.Write("———————————————————————————————————————————");

public interface IBank
{
    void credit();
    void withdraw();
}
public class WhiteBank : IBank
{
    public void credit()
    {
        Console.WriteLine("Your balance is credited in WhiteBank account");
    }
    public void withdraw()
    {
        Console.WriteLine("\nCash withdrew from WhiteBank account");
    }
}
public class GreenBank : IBank
{
    public void credit()
    {
        Console.WriteLine("Your balance is credited in GreenBank account");
    }
    public void withdraw()
    {
        Console.WriteLine("\nCash withdrew from GreenBank account");
    }
}
Output
kodingwindow@kw:~/csharp$ dotnet run
———————————————————————————————————————————
Program to demonstrate the use of interface
———————————————————————————————————————————
Your balance is credited in GreenBank account

Cash withdrew from WhiteBank bank account
———————————————————————————————————————————
kodingwindow@kw:~/csharp$ 
Advertisement