下面的是《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.
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.