Example details based on c interface

  • 2020-05-17 06:09:37
  • OfStack


namespace ConsoleApplication1
{
    using System;
    using System.Collections.Generic;
    using System.Text;
    public class BankMethod : IBankAccount
    {
        decimal balance;
        public void PayIn(decimal Account)
        {
            balance += Account;
            //Console.WriteLine(" Your present deposit is :{0}",balance);
        }
        public bool PayOut(decimal Account)
        {
            if (Balance > Account)
            {
                balance -= Account;
                Console.WriteLine(" You have already taken it {0}, And then we have the remaining balance :{1}", Account, balance);
                return true;
            }
            Console.WriteLine(" Withdrawal failed! ");
            return false;
        }
        public decimal Balance
        {
            get { return balance; }
        }
        public override string ToString()
        {
            return string.Format(" Your present deposit is :{0:C}", balance);
        }
    }
    class Test
    {
        static void Main()
        {
            IBankAccount Huguo = new BankMethod();
            IBankAccount guo = new BankMethod();
            Huguo.PayIn(10000);
            guo.PayIn(200000);
            Console.WriteLine(Huguo.ToString());
            Console.WriteLine(guo.ToString());
            //BankMethod Bank = new BankMethod();
            //Bank.PayIn(200000);
            //Bank.PayOut(30000);
        }
    }
}


namespace ConsoleApplication1
{
    public interface IBankAccount
    {
        void PayIn(decimal amount);
        bool PayOut(decimal amount);
        decimal Balance
        {
            get;
        }
    }
    public interface IBankTransfer:IBankAccount
    {
        bool Transfer(IBankAccount Action,decimal amount);
    }
}


Related articles: