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

前端 未结 7 586
轻奢々
轻奢々 2020-12-15 15:05

I\'m not sure why i\'m getting this error to be honest.

private int hour
{
    get;
    set
    {
        //make sure hour is positive
        if (value <         


        
7条回答
  •  时光取名叫无心
    2020-12-15 15:27

    Try this:

    private int hour;
    public int Hour
    {
        get { return hour; }
        set
        {
            //make sure hour is positive
            if (value < MIN_HOUR)
            {
                hour = 0;
                MessageBox.Show("Hour value " + value.ToString() + " cannot be negative. Reset to " + MIN_HOUR.ToString(),
                "Invalid Hour", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                //take the modulus to ensure always less than 24 hours
                //works even if the value is already within range, or value equal to 24
                hour = value % MAX_HOUR;
            }
        }
    }
    

提交回复
热议问题