int num;
num = Convert.ToInt32(Console.ReadLine());
Convert.ToInt32() 把用户输入的数据转换为 int 数据类型,因为 Console.ReadLine() 只接受字符串格式的数据。
// See https://aka.ms/new-console-template for more information
using System;
namespace HelloWorld
{
class Program
{
static void Main()
{
string characterName = "yulin";
int age = 20;
Console.WriteLine("There was a person named " + characterName);
Console.WriteLine("Hello, World!");
Console.WriteLine("age is "+ age);
int num = Convert.ToInt16(Console.ReadLine());
Console.WriteLine("num is " + num);
}
}
}