using System;
namespace Rndom
{
class MainClass
{
public static void Main(string[] args)
{
start:
Random obj = new Random();
int num1 = obj.Next(1, 9);
int num2 = obj.Next(10,21);
Console.WriteLine("sum of two unique numbers\n"+num1+" "+num2+" "+(num1+num2));
char ch;
Console.WriteLine("If wannt to continue, press y");
ch = Convert.ToChar(Console.ReadKey()); // <- I have exception thrown here
if(ch=='y')
{
goto start;
}
else
{
Console.WriteLine("press any key to terminate");
Console.ReadKey();
}
}
}
}
答案 0 :(得分:2)
而不是
ch = Convert.ToChar(Console.ReadKey());
你应该把它作为
ch = Console.ReadKey().KeyChar;
由ConsoleKeyInfo
返回的Console.ReadKey()
实例无法转换到char