揭会员对象作为属性或方法在.NET [英] Exposing Member Objects As Properties or Methods in .NET

查看:241
本文介绍了揭会员对象作为属性或方法在.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在.NET中,如果一个类包含一个成员是一类对象,应该成员可以公开为属性或方法?

In .NET, if a class contains a member that is a class object, should that member be exposed as a property or with a method?

推荐答案

如果你正在做的是暴露一个对象实例,是有关你应该使用属性的当前对象的状态。

If all you are doing is exposing an object instance that is relevant to the state of the current object you should use a property.

当你有一些逻辑是做多的内存对象访问一个并返回一个值时,或者正在执行,有一个对当前对象的状态广泛影响的操作方法应该被使用。

A method should be used when you have some logic that is doing more than accessing an in memory object and returning that value or when you are performing an action that has a broad affect on the state of the current object.

这篇关于揭会员对象作为属性或方法在.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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