这个类的构造函数应该生成一个关于被随机选择的人的随机提示,并将该提示存储在它的random hint属性中。似乎我的两个构造函数都有问题,但是我不知道如何解决这个问题或者问题是什么…有什么好主意吗?
class RandomHintGame : Game
{
string randomHint;
static Random r = new Random();
// Constructor 1
public RandomHintGame(string randomHint, Person person) : base(person)
{
this.randomHint = randomHint;
}
// Constructor 2
public RandomHintGame(Person person) : this(person)
{
int randomNumber = r.Next(0, 3);
switch (randomNumber)
{
case 0: randomHint = $"The person {HasHat} a hat."; break;
case 1: randomHint = $"The person has {EyeColor} eyes."; break;
case 2: randomHint = $"The person is a {Gender}"; break;
}
}
}
int randomNumber = r.Next(0, 3);
将返回0,1,2参见链接
你的交换机是123,200
构造函数2的基不是这个
// Constructor 2
public RandomHintGame(Person person) : base(person)