方法必须有返回类型(C#)

coo*_*uss 2 c# methods return

所以我一直在用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);
}
Run Code Online (Sandbox Code Playgroud)

但是我收到一个错误:方法必须有返回类型.指的是"PrintAccount(RobAccount);"

我知道之前已经问过这个问题,但没有一个问题与我的问题类似.

Cla*_*edi 8

问题是编译器认为这PrintAccount(RobsAccount);是一个方法定义,这就是为什么需要返回类型.

你必须在另一个方法中调用该方法,你不能在void上调用它.