Csharp/C#教程:基于c# 接口的实例详解分享

代码如下:
namespaceConsoleApplication1
{
   usingSystem;
   usingSystem.Collections.Generic;
   usingSystem.Text;
   publicclassBankMethod:IBankAccount
   {
       decimalbalance;
       publicvoidPayIn(decimalAccount)
       {
           balance+=Account;
           //Console.WriteLine(“您现在的存款是:{0}”,balance);
       }
       publicboolPayOut(decimalAccount)
       {
           if(Balance>Account)
           {
               balance-=Account;
               Console.WriteLine(“您已经取走了{0},还剩下余额是:{1}”,Account,balance);
               returntrue;
           }
           Console.WriteLine(“提款失败!”);
           returnfalse;
       }
       publicdecimalBalance
       {
           get{returnbalance;}
       }
       publicoverridestringToString()
       {
           returnstring.Format(“您现在的存款是:{0:C}”,balance);
       }
   }
   classTest
   {
       staticvoidMain()
       {
           IBankAccountHuguo=newBankMethod();
           IBankAccountguo=newBankMethod();
           Huguo.PayIn(10000);
           guo.PayIn(200000);
           Console.WriteLine(Huguo.ToString());
           Console.WriteLine(guo.ToString());
           //BankMethodBank=newBankMethod();
           //Bank.PayIn(200000);
           //Bank.PayOut(30000);
       }
   }
}

代码如下:
namespaceConsoleApplication1
{
   publicinterfaceIBankAccount
   {
       voidPayIn(decimalamount);
       boolPayOut(decimalamount);
       decimalBalance
       {
           get;
       }
   }
   publicinterfaceIBankTransfer:IBankAccount
   {
       boolTransfer(IBankAccoun tAction,decimalamount);
   }
}

您可能感兴趣的文章:接口对象的实例化在接口回调中的使用方法C#接口实现方法实例分析C#实例化接口对象的方法

标签: 接口 c#

C++设置超时时间的简单实现方法

深入IComparable与IComparer的排序实例详解

上述就是C#学习教程:基于c# 接口的实例详解分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/904858.html

(0)
上一篇 2021年10月22日
下一篇 2021年10月22日

精彩推荐