主题:[讨论]方法重载问题
using System;
namespace SavingsAccount
{
/// <summary>
/// 创建SavingsAccount类,用Static变量annualInsterestRate来存储利率。对所有的帐户持有者,该类的每个对象都有一个Private实例变量SavingsBalance,指明储户当前存款的数量,CalculateMondifyInteres
/// t方法通过SavingsBalance乘以annualInterestRate除以12来按月计算利息。
/// </summary>
class SavingsAccount
{
private static string name;//姓名
private double annualInsterestRate;//存储利率
private static double SavingsBalance;//储户当前存款的数量
private double Interest;//月利息
private double Increase;//余额
public void Print()
{
Console.WriteLine("姓名:{0}",name);
Console.WriteLine("基本工资:{0}",SavingsBalance);
Console.WriteLine("用户月利息:{0,5:c}",Interest);
Console.WriteLine("余额:{0,5:c}",Increase);
}
public void CalculateMondifyInterest(double annualInsterestRate)//计算利息的方法
{
Interest=annualInsterestRate*SavingsBalance/12.0;
}
static void ModifyInterestRate(string n,double a)
{
name=n;
SavingsBalance=a;
}
}
class Program
{
public static void Main(string[] args)
{
SavingsAccount [] e=new SavingsAccount[2];//定义对象数组
e[0]=[color=FF0000]new [/color]SavingsAccount("saver1",2000.00);//使用构造方法实例化对象
e[1]=[color=FF0000]new[/color] SavingsAccount("saver2",3000.00);
e[0].CalculateMondifyInterest(0.04);
e[1].CalculateMondifyInterest(0.04);
e[0].CalculateMondifyInterest(0.05);
e[1].CalculateMondifyInterest(0.05);
foreach(SavingsAccount E in e)
{
E.Print();
Console.WriteLine();
}
Console.Read();
}
}
}
也不知道每次调试的时候总是弹出:重载“SavingsAccount”方法未获取“2”参数(红色部分)
[em19]
namespace SavingsAccount
{
/// <summary>
/// 创建SavingsAccount类,用Static变量annualInsterestRate来存储利率。对所有的帐户持有者,该类的每个对象都有一个Private实例变量SavingsBalance,指明储户当前存款的数量,CalculateMondifyInteres
/// t方法通过SavingsBalance乘以annualInterestRate除以12来按月计算利息。
/// </summary>
class SavingsAccount
{
private static string name;//姓名
private double annualInsterestRate;//存储利率
private static double SavingsBalance;//储户当前存款的数量
private double Interest;//月利息
private double Increase;//余额
public void Print()
{
Console.WriteLine("姓名:{0}",name);
Console.WriteLine("基本工资:{0}",SavingsBalance);
Console.WriteLine("用户月利息:{0,5:c}",Interest);
Console.WriteLine("余额:{0,5:c}",Increase);
}
public void CalculateMondifyInterest(double annualInsterestRate)//计算利息的方法
{
Interest=annualInsterestRate*SavingsBalance/12.0;
}
static void ModifyInterestRate(string n,double a)
{
name=n;
SavingsBalance=a;
}
}
class Program
{
public static void Main(string[] args)
{
SavingsAccount [] e=new SavingsAccount[2];//定义对象数组
e[0]=[color=FF0000]new [/color]SavingsAccount("saver1",2000.00);//使用构造方法实例化对象
e[1]=[color=FF0000]new[/color] SavingsAccount("saver2",3000.00);
e[0].CalculateMondifyInterest(0.04);
e[1].CalculateMondifyInterest(0.04);
e[0].CalculateMondifyInterest(0.05);
e[1].CalculateMondifyInterest(0.05);
foreach(SavingsAccount E in e)
{
E.Print();
Console.WriteLine();
}
Console.Read();
}
}
}
也不知道每次调试的时候总是弹出:重载“SavingsAccount”方法未获取“2”参数(红色部分)
[em19]