有没有办法将ActionType作为参数传递给一个新方法?我想将新的单一方法称为另外两种不同的方法(提取和存款)。
class Account
{
enum ActionType
{
Withdraw,
Deposit,
}
private void WriteDeposit()
{
StreamWriter outputFile;
outputFile = File.AppendText("account.log");
outputFile.WriteLine("{0},{1}", DateTime.Now, ActionType.Deposit);
outputFile.Close();
}
private void WriteWithdraw()
{
StreamWriter outputFile;
outputFile = File.AppendText("account.log");
outputFile.WriteLine("{0},{1}", DateTime.Now, ActionType.Withdraw);
outputFile.Close();
}
答案 0 :(得分:2)
根据您的问题,以下内容应该有效。
class Account
{
enum ActionType
{
Withdraw,
Deposit,
}
public void Withdraw()
{
WriteAction(ActionType.Withdraw);
}
private void WriteAction(ActionType action)
{
StreamWriter outputFile;
outputFile = File.AppendText("account.log");
outputFile.WriteLine("{0},{1}", DateTime.Now, action);
outputFile.Close();
}
}