请看一下客户类的这个简单实现:
class Customer
{
public double TotalPurchases { get; set; }
public string Name { get; set; }
public int CustomerID { get; set; }
public Customer(double purchases, string name, int ID)
{
TotalPurchases = purchases;
Name = name;
CustomerID = ID;
}
}
我注意到客户名称有一个获取和设置选项。假设我需要更改客户名称。
通过如下方法更改客户名称是否更容易接受:
public void changeName(string name)
{
this.Name = name;
}
Customer cus = new Customer(5,"John",5005);
cus.changeName("Jim");
还是可以通过以下方式更改它:
cus.Name = "Jim";