什么是具有非平凡实现的getter? [英] what is mean getters with non-trivial implementations?

查看:71
本文介绍了什么是具有非平凡实现的getter?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我想知道我的财产是什么获得了非常琐碎的实施?。

推荐答案

一个简单的实现就是getter只返回私有字段的值



A trivial implementation would be one where the getter simply returns the value of a private field

private string _fullname;
public string Fullname
{
    get
    {
        return _fullname;
    }
}





一个非常重要的例子可能是一个做一些非平凡事情的getter,比如





A non trivial example might be a getter that does something non - trivial, such as

public decimal TaxAmount
{
    get
    {
         decimal taxRate = GetTaxRate(Income);
         decimal taxable = Income - TaxFreePay(Income);
         return taxable * taxRate;
    }
}





换句话说,非平凡的实现只是它说的是什么 - 一个不是微不足道的实现。



In other words, a non trivial implementation is just what it says - an implementation that is not trivial.


这篇关于什么是具有非平凡实现的getter?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆