【发布时间】:2021-12-29 20:12:25
【问题描述】:
我有一个带有构造函数的结构:
public struct Time
{
public Time(int minutes)
: this()
{
this.Minutes = minutes;
}
public Time(int hours, int minutes)
: this(minutes)
{
this.Hours = hours;
}
我需要帮助来创建一个属性(只读),它允许我以 24 小时格式( 00.XX - 23.XX )指示小时数。如上所述,我通过调用构造函数来提供属性的值。我目前未完成的尝试:
public readonly int Hours { get; }
很高兴听到任何建议。干杯!
【问题讨论】:
-
你为什么不用
TimeSpan? -
很遗憾,我不允许使用 TimeSpan。这是一项任务。
-
你可以为你的
get { return something; }提供一个块
标签: c# constructor