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

前端 未结 7 593
轻奢々
轻奢々 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:36

    You can just use the keywork value to accomplish this.

    public int Hour {
        get{
            // Do some logic if you want
            //return some custom stuff based on logic
    
            // or just return the value
            return value;
        }; set { 
            // Do some logic stuff 
            if(value < MINVALUE){
                this.Hour = 0;
            } else {
                // Or just set the value
                this.Hour = value;
            }
        }
    }
    

提交回复
热议问题