c# – 仅在.NET中没有相应字段的情况下使用属性的缺点?

栏目: ASP.NET · 发布时间: 7年前

内容简介:我的问题是,只使用没有相应字段的属性有什么缺点?我可以将setter或getter设为私有,内部..等等,这意味着我还可以在需要时灵活地确定范围.翻译自:https://stackoverflow.com/questions/1080753/disadvantages-of-using-properties-only-with-no-corresponding-fields-in-net

我的问题是,只使用没有相应字段的属性有什么缺点?我可以将setter或getter设为私有,内部..等等,这意味着我还可以在需要时灵活地确定范围.

使用BinaryFormatter进行序列化 – 如果您需要稍后将属性更改为“常规”属性,例如添加一些验证/事件/等,则会遇到大问题 – sinc BinaryFormatter使用字段名称.而且你不能复制它,因为编译器生成的字段名称不能写成合法的C#.

这是查看基于合同的序列化器的一个很好的理由.有关详细信息,请参阅 this blog entry .

翻译自:https://stackoverflow.com/questions/1080753/disadvantages-of-using-properties-only-with-no-corresponding-fields-in-net


以上所述就是小编给大家介绍的《c# – 仅在.NET中没有相应字段的情况下使用属性的缺点?》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。

Understanding Machine Learning

Understanding Machine Learning

Shai Shalev-Shwartz、Shai Ben-David / Cambridge University Press / 2014 / USD 48.51

Machine learning is one of the fastest growing areas of computer science, with far-reaching applications. The aim of this textbook is to introduce machine learning, and the algorithmic paradigms it of......一起来看看 《Understanding Machine Learning》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

在线进制转换器
在线进制转换器

各进制数互转换器