如何查找从键盘输入的值的类型?

How do I find type of value entered from the keyboard?

如何在 C# consol 应用程序中使用方法显示从键盘输入的值的类型?

static void Main(string[] args)
{
    int yas;
    Console.Write("Enter Your Age: ");

    yas = int.Parse(Console.ReadLine());

    Console.WriteLine("You're {0} years old.", yas);

}

在示例中的应用程序中,我只希望您的用户输入数值数据,但我尝试使用 typeof 进行输入时出现错误。你能帮帮我吗?

我不想更改变量的类型。我想让你的用户再次想要价值而不是 int。输入值时解析错误

I want to make your user want value again instead of int.parse error when entering a value

您可以使用评论中提到的方法不断询问输入,直到输入正确为止:

static void Main(string[] args)
{
    int yas;

    do { // until the user input is valid, keep asking
        Console.Write("Yaşınız Giriniz: ");
    } while (!int.TryParse(Console.ReadLine(), out yas));

    Console.WriteLine("Demek {0} yaşınızdasınız", yas);
}