我的人班:
class Person
{
public string FirstName { get; private set; }
public string LastName { get; private set; }
public int Age { get; private set; }
public Person(string firstName,string LastName,int age)
{
this.FirstName = firstName;
this.LastName = LastName;
this.Age = age;
}
public override string ToString()
{
return this.FirstName + " " + this.LastName + " " + this.Age;
}
}
主要的:
class Program
{
static void Main(string[] args)
{
Person sallyPerson = new Person("Sally", "Solomon",23);
}
}
假设我想更改此人的名字和年龄,我该怎么做?FirstName 和 Age 属性是私下设置的。