简体   繁体   中英

C# must declare a body because it is not marked abstract, extern, or partial

Hey I am trying to create a constructor so I can display the name and balance of a test account, but i'm not sure what to do. any help would be greatly appreciated, as I am new to programmin, and haven't been doing it for long.

public class Account
{

    public Account (string Name, decimal balance);

    public string name;

    private decimal balance;


    public string GetName()
    {
        return name;
    }

    static decimal MaxPayInAmount = 10000;

    public bool PayInFunds(decimal amount)
    {

        if (amount < 0)
        {
            return false;
        }

        if (amount > MaxPayInAmount)
        {
            return false;
        }

        balance = balance + amount;

        return true;
    }


    public bool SetName(string inname)
    {
        if (inname == "")
            return false;

        name = inname;
        return true;
    }

    public Account(string inName)
    {
        name = inName;
    }


    public decimal GetBalance()
    {
        return balance;
    }

}

Your constructor does not have a method body. Use this instead:

public Account (string name, decimal balance)
{
    this.name = name;
    this.balance = balance;
}

Also you should follow some naming conventions (eg you made one parameter with capital letter and one in lowercase)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM