如何随机使用int来使用它? 我得到的错误: CS0029无法将类型'System.Random'隐式转换为'int'
Console.Write("How old am i? Guess!");
string randomguess = Console.ReadLine();
Console.WriteLine("My age is " + (random.Next(1, 101)));
int newrandomguess = Convert.ToInt32(randomguess);
if(newrandomguess == random)
{
Console.WriteLine("Oh you guessed my age correctly! Im surprised.");
}
else
{
Console.WriteLine("As i expected, u guessed wrong..");
}
答案 0 :(得分:0)
创建一个新的随机值:
int randomValue = random.Next(1, 101);
使用该随机值写出控制台:
Console.WriteLine("My age is " + randomValue);
将猜测与值进行比较:
if (randomGuess == randomValue)
{
...
}