C#类中的条件属性

C#类中的条件属性,c#,C#,我有这个代码,它根据收入值以指定的比率计算会费。 详情如下: public decimal Income { get; set; } public decimal Rate { get; set; } public string Dues { get { return string.Format("{0}", Math.Round((this.Income * (1 /this.Rate) * 0.01m), 2)); } } 我想做的是检查会费计算是

我有这个代码,它根据收入值以指定的比率计算会费。 详情如下:

public decimal Income { get; set; }
public decimal Rate { get; set; }
public string Dues
{
    get 
    {
        return string.Format("{0}", Math.Round((this.Income * (1 /this.Rate) * 0.01m), 2));
    }
}
我想做的是检查会费计算是否小于5.00,然后它应该将会费值设置为5.00。我不确定这是否可以做到

如有任何帮助,我们将不胜感激。

请写以下内容:

public class Foo
{
    public decimal Income { get; set; }
    public decimal Rate { get; set; }
    public decimal Dues
    {
        get
        {
            decimal totalDues = Math.Round((this.Income * (1 / this.Rate) * 0.01m), 2);
            return totalDues >= 5.00M ? totalDues : 5.00M;
        }
    }
}
写如下:

public class Foo
{
    public decimal Income { get; set; }
    public decimal Rate { get; set; }
    public decimal Dues
    {
        get
        {
            decimal totalDues = Math.Round((this.Income * (1 / this.Rate) * 0.01m), 2);
            return totalDues >= 5.00M ? totalDues : 5.00M;
        }
    }
}