有人告诉我,在 C# 中,属性不允许用于自动实现的属性。真的吗?如果是,为什么?
编辑:我从一本关于 LINQ 的畅销书中获得了这些信息,简直不敢相信! 编辑:请参阅 Paul Kimmel 的 LINQ Unleashed 第 34 页,他说“自动实现的属性不允许使用属性,因此如果需要属性,请自己动手”
最佳答案
您可以毫无问题地将属性应用于自动属性。
引自 MSDN :
Attributes are permitted on auto-implemented properties but obviously not on the backing fields since those are not accessible from your source code. If you must use an attribute on the backing field of a property, just create a regular property.
关于c# - 自动实现的属性是否支持特性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/464889/