C# 中为什么没有泛型属性

下面的是《CLR via C#》中对这个问题的解释,但不很清楚对,对属性的”behavior“这个概念描述不清楚。请作出说明,最好有示例,谢谢!

Generic Property Accessor Methods:
Since properties are really just methods, and because C# and the CLR allow methods to be
generic, sometimes people try to define generic property accessor methods. However, C#
does not allow this. The main reason why generic properties are not allowed is because they
don't make sense conceptually. A property is supposed to represent a characteristic of an
object that can be queried or set. Adding a generic type parameter would mean that the behavior
of the querying/setting could be changed, but conceptually, a property is not supposed to
have behavior. If you want your object to expose some behavior—generic or not—define a
method, not a property.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值