Onl*_*ere 4 .net c# object value-type reference-type
请考虑以下示例.
我需要检查CouponModel是否有唯一的串行密钥.
我有两个选择:
CouponModel model = GetFromSomewhere();
if (!CouponHasUniqueKey(model))
{
}
//or
if (!CouponHasUniqueKey(model.SerialKey))
{
}
Run Code Online (Sandbox Code Playgroud)
当然,在我传入整个对象的方法中,我必须访问字符串属性,而不是直接使用字符串.
哪个选项更好,为什么?
我相信表现会一样.
我也更愿意对对象本身负责:
CouponModel coupon = GetFromSomewhere();
if (!coupon.HasUniqueKey()) {
// ...
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
134 次 |
| 最近记录: |