C#方法定义和调用-2

时间:2023-12-31 12:59:44
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace ConsoleApplication1
{
class Qian
{
private decimal yuanlai;
private string name;
public Qian(string name)
{
this.yuanlai = ;
this.name = name;
Print("我的钱数", );
} public bool Desposit(decimal jine)
{
if (jine <= )
return false;
yuanlai += jine;
Print("借了别人",jine);
return true;
} public bool WithDraw(decimal jine)
{
if (jine > yuanlai || jine <= )
return false;
yuanlai -= jine;
Print("借给别人", jine);
return true;
} private void Print(string operation, decimal jine)
{
Console.WriteLine("我的名字:{0}",name);
Console.WriteLine("{0}:{1}",operation,jine);
Console.WriteLine("现在的钱:{0}",yuanlai);
Console.WriteLine("============================");
Console.ReadKey();
}
}
class Program
{
static void Main(string[] args)
{
Qian q = new Qian("我是LT");
bool succed = q.Desposit();
if (!succed)
Console.WriteLine("他不借给我钱!");
succed = q.WithDraw();
if (!succed)
Console.WriteLine("我不借给他钱!");
Console.ReadKey(); }
}
}