加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Program.cs 2.15 KB
一键复制 编辑 原始数据 按行查看 历史
詹超凡 提交于 2022-04-02 12:00 . update Program.cs.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace studentwork
{
class Savings
{
int RemainingSum = 20000;
Credit x; //信用
public Savings(Credit x)
{
this.x = x;
}
public void DeductMoney() //扣款
{
if (x.CheckPayment() == 1)
{
RemainingSum = RemainingSum - x.GetAmountPending();
Console.WriteLine("还款成功,余额为:{0}", RemainingSum);
}
else
{
Console.WriteLine("不需要还款,余额为:{0}", RemainingSum);
}
}
}
class Credit
{
int DueDate = 29;
int AmountPending;
int DateOfRepayment;
public Credit(int RepaymentAmount, int RepaymentDate)
{
this.AmountPending = RepaymentAmount;
this.DateOfRepayment = RepaymentDate;
}
public int GetAmountPending()
{
return AmountPending;
}
public int CheckPayment()
{
if (DueDate == DateOfRepayment)
return 1;
else
return 0;
}
}
class Delegate
{
public delegate void pay();
public event pay payment;
public void Notify()
{
if (payment != null)
{
Console.WriteLine("触发事件:");
payment();
}
}
}
class Program
{
static void Main(string[] args)
{
Delegate objDelegate = new Delegate();
Credit a1 = new Credit(1000, 27);
Credit a2 = new Credit(1000, 29);
Savings b1 = new Savings(a1);
Savings b2 = new Savings(a2);
objDelegate.payment +=
new Delegate.pay(b1.DeductMoney);
objDelegate.payment +=
new Delegate.pay(b2.DeductMoney);
objDelegate.Notify();
Console.ReadLine();
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化