访问修饰符的目的是隐藏数据成员免受未经授权的访问。而 Properties 的目的是公开访问修饰符。访问修饰符的目的消失了。以下是示例。
public class Employee
{
private int EmployeeID;
private string Name;
private int Salary;
public int EID { get { return this.EmployeeID; } set { this.EmployeeID = value; } }
public string EName { get { return this.Name; } set { this.Name = value; } }
public int ESalary { get { return this.Salary; } set { this.Salary = value; } }
}
static void Main(string[] args)
{
Employee Employee = new Employee();
Employee.EName = "Zaheer";
}
在这里我可以访问间接访问名称的属性 EName。如果问题很愚蠢,请发表任何评论并抱歉。