【发布时间】:2011-07-04 05:19:02
【问题描述】:
嗯,我正在学习属性,但我不确定以下内容:
class X
{
private int y;
public X(int number)
{
this.Y=number; // assign to property
OR
this.y=number //?
}
public int Y;
{
get; set;
}
}
【问题讨论】:
-
你的代码有问题。 private int y 与 public int Y 无关。这是一个最佳实践问题,因此请查看@Fredrik Mörk 建议的链接。
标签: c# .net properties automatic-properties