An Immutable Class
一个简单的Immutable Class:
class Contact
{
public Contact(String fullName, String phoneNumber)
{
this.fullName= fullName;
this.phoneNumber= phoneNumber;
}
public Contact ChangeNumber(String newNumber)
{
//创建一个新实例
return new Contact (this.fullName, newNumber);
}
readonly String fullName;
public String FullName { get { return fullName; }}
readonly String phoneNumber;
public uint PhoneNumber{ get { return phoneNumber; }}
}
{
public Contact(String fullName, String phoneNumber)
{
this.fullName= fullName;
this.phoneNumber= phoneNumber;
}
public Contact ChangeNumber(String newNumber)
{
//创建一个新实例
return new Contact (this.fullName, newNumber);
}
readonly String fullName;
public String FullName { get { return fullName; }}
readonly String phoneNumber;
public uint PhoneNumber{ get { return phoneNumber; }}
}