简体   繁体   English

如何在不使用变量的情况下输出Console.ReadLine()的输入

[英]How To Output The Input of Console.ReadLine() Without Using A Variable

I have a quick question that I could not find the answer to on google (probably because of the extreme uselessness of the real life application). 我有一个快速的问题,我在Google上找不到答案(可能是由于现实应用程序的极端无用)。 My C# instructor Has a "challenge" ie homework where we cannot use variables of any kind. 我的C#讲师有一个“挑战”,即作业,我们不能使用任何类型的变量。 There is only one input, the year. 只有一年的输入。 Does anyone know how to output the year as an int or have some sort of article that could help with this? 有谁知道如何将年份输出为int或有某种文章可以对此有所帮助? Example Code: 示例代码:

Console.WriteLine("Please enter the year: ");
Console.ReadLine();
Console.WriteLine(int.Parse(Console.ReadLine));

TIA, Any answer is appreciated! TIA,任何答复表示赞赏! (For anyone who is curious the homework is to make an Easter Sunday Calculator) (对于好奇的人,作业是做一个复活节星期天计算器)

Just use: 只需使用:

Console.WriteLine(int.Parse(Console.ReadLine()));

or 要么

Console.WriteLine(Convert.ToInt32(Console.ReadLine()));

Console.ReadLine() is a function and so it should be used with parentheses () . Console.ReadLine()是一个函数,因此应与括号()一起使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM