c# - 自动实现的属性是否支持特性?

标签 c# attributes automatic-properties

有人告诉我,在 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/

相关文章:

c# - SQL Server中如何获取同一日期之间的记录

c# - 我应该在读取 ElapsedMilliseconds 之前调用 Stop 吗?

c# - 异步TCP套接字的怪异行为

c# - 自动实现属性的代码契约(Contract)

ios - Xcode 5.1.1 中没有自动下划线 ivar

c# - 使用 BinaryFormatter 将自动实现的属性更改为正常和反序列化

c# - 如何在不覆盖当前数据的情况下将数据写入文本文件

django - 如何将类、id、占位符属性添加到 django 模型表单中的字段

python - 该对象在 Django 中没有属性 'is_hidden'

Django - 应用过滤器时无法访问对象属性