对于学校作业,我应该创建一个可以按小时,分钟和秒存储时间的Time类.一切都工作正常,但只有声明得到时,属性总是返回0; 并设定;
private int seconds, minutes, hours;
public int Seconds { get; set; }
public int Minutes { get; set; }
public int Hours { get; set; }
Run Code Online (Sandbox Code Playgroud)
如果我在getter中定义要返回的内容,它可以正常工作:
private int seconds, minutes, hours;
public int Seconds { get { return this.seconds; } set { this.seconds = value; } }
public int Minutes { get { return this.minutes; } set { this.minutes = value; } }
public int Hours { get { return this.hours; } set { this.hours = value; } }
Run Code Online (Sandbox Code Playgroud)
我真的不介意编写这些额外的代码,但根据我的理解,第一段代码应该可以正常工作.这里发生了什么?