公共变量 - 需要属性 C# [英] public variables - need of properties C#

查看:47
本文介绍了公共变量 - 需要属性 C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
C#:公共字段与自动属性

我读过 C# 中的属性被声明或用于向其他人提供私有成员的访问.在这种情况下,当我们声明公共成员时,我们是否仍然需要为他们声明属性.

I read properties in C# are declared or used to provide access of private members to others. In that case, when we are declaring public members, do we still have to declare properties for them.

在下面的例子中,他们为公共成员声明了属性.不知道为什么?

In the following example, they have declared properties for public members. I don't know why ?

class Customer
{
     public double TotalPurchases { get; set; }
     public string Name { get; set; }
     public int CustomerID { get; set; }
}

谢谢!

推荐答案

这篇文章很好地概述了属性及其过度使用http://www.codinghorror.com/blog/2006/08/properties-vs-public-variables.html

This article gives you a good overview to properties and its overuse http://www.codinghorror.com/blog/2006/08/properties-vs-public-variables.html

这篇关于公共变量 - 需要属性 C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆