所以我一直在关注 C# 这本书。
http://www.robmiles.com/c-yellow-book/Rob%20Miles%20CSharp%20Yellow%20Book%202011.pdf 第 81-82 页我从那里获取此代码并从第 82 页添加另一种方法,结果是:
using System;
enum AccountState
{
New,
Active,
UnderAudit,
Frozen,
Closed
};
struct Account
{
public AccountState State;
public string Name;
public string Address;
public int AccountNumber;
public int Balance;
public int Overdraft;
};
class Bankprogram
{
public static void Main()
{
Account RobsAccount;
RobsAccount.State = AccountState.Active;
RobsAccount.Name = "Rob Miles";
RobsAccount.AccountNumber = 1234;
RobsAccount.Address = "his home";
RobsAccount.Balance = 0;
RobsAccount.Overdraft = -1;
Console.WriteLine("name is " + RobsAccount.Name);
Console.WriteLine("balance is : " + RobsAccount.Balance );
}
public void PrintAccount(Account a)
{
Console.WriteLine ("Name" + a.Name);
Console.WriteLine ("Address :" + a.Address);
Console.WriteLine ("Balance:" + a.Balance);
}
PrintAccount(RobsAccount);
}
但我得到一个错误:方法必须有返回类型。指的是“PrintAccount(RobAccount);”
我知道以前有人问过这个问题,但没有一个看起来与我的问题相似。