我在一个简单的输入和输出程序中遇到问题

本文关键字:输出 输入 程序 问题 遇到 简单 一个 | 更新日期: 2023-09-27 17:56:20

好的 所以当我想放这一行时,我使用 visual c#

enter code here


static void Main(string[] args)
        {
            Console.ReadLine a, b, c, max;
        }
    }
}

但它说这个关于 ReadLine 部分的错误:类型名称"ReadLine"在类型"控制台"中不存在

我在一个简单的输入和输出程序中遇到问题

Console.ReadLine 是一个方法,所以应该像这样使用:

Console.WriteLine("Enter something"); //this will print the text to the screen
string inputText = Console.ReadLine(); // Get string from the input and assign it to the inputText variable

您可以在此处查看其他参考。

这是什么???请先阅读 MSDN 文档。错误是原因ReadLine()它是一个方法,但您正在尝试将其本身用作类型。假设您已经声明了一个名为 a 的变量并且它是 string 类型的变量,它应该就在下面。

a = Console.ReadLine();

阅读 Console.ReadLine 方法 ()。 文档有几个很好的例子,这将有助于消除你的疑问。