【发布时间】:2018-06-07 12:17:33
【问题描述】:
在 C# 中,我注意到许多编码人员会执行以下操作:
class X
{
private int test_;
public int test
{
get { return test_; }
set { if (test_ != value) test_ = value; }
}
}
我的问题是为什么要为相同的内容保留一个私有变量和一个公共变量?
为什么我们不这样做呢?
class X
{
public int test
{
get; set;
}
}
我的意思是,无论如何我们都在更改私有变量。不使用单个公共变量有什么意义?
【问题讨论】:
标签: c# uwp windows-10-universal