小编Jon*_*Jon的帖子

在参数 C# 中传递接口

图片

传入参数有什么好处?我们可以从中获得什么?目的是什么?

interface IBankAccount
{
    void PayIn(decimal amount);
    bool Withdraw(decimal amount);
    decimal Balance { get; }
}

interface ITransferBankAccount : IBankAccount
{
    bool TranferTo(IBankAccount destination, decimal amount);
}

class CurrentAccount : ITransferBankAccount
{

    public bool TranferTo(IBankAccount destination, decimal amount)
    {
        bool result;
        result = Withdraw(amount);
        if (result)
        {
            destination.PayIn(amount);
        }
        return result;
    }



    public decimal Balance
    {
        get
        {
            throw new NotImplementedException();
        }
    }

    public void PayIn(decimal amount)
    {
        throw new NotImplementedException();
    }





  public bool Withdraw(decimal amount)
    {
        throw new NotImplementedException(); …
Run Code Online (Sandbox Code Playgroud)

c# parameters interface

3
推荐指数
2
解决办法
7608
查看次数

标签 统计

c# ×1

interface ×1

parameters ×1