无法输入值

本文关键字:输入 | 更新日期: 2023-09-27 18:06:25

我刚开始学习c#。我复制了一个样本从visual basic网站:http://msdn.microsoft.com/en-us/library/aa288457(v=vs.71).aspx

在示例中:

// cmdline1.cs
// arguments: A B C
    using System;
public class CommandLine
{
   public static void Main(string[] args)
   {
       // The Length property is used to obtain the length of the array.
       // Notice that Length is a read-only property:
       Console.WriteLine("Number of command line parameters = {0}",
          args.Length);
       for(int i = 0; i < args.Length; i++)
       {
           Console.WriteLine("Arg[{0}] = [{1}]", i, args[i]);
       }
   }
}

我不知道怎么在这里输入

当我运行代码时,没有办法输入值,有人知道为什么吗?

无法输入值

您的程序不是用来接受任何输入的。它只是打印命令行参数和参数的数量。它也写在你张贴的链接。为什么需要输入呢?

Console.WriteLine()输出,使用Console.ReadLine()接收输入。

下面的代码会询问你的名字,然后打印出来:

static void Main(string[] args)
{
    // Prints a user understandable message
    Console.WriteLine("Enter your Name:");
    // takes input and store it in a string variable
    string name = Console.ReadLine();
    // print output 
    Console.WriteLine("Hello " + name);
}

有两种方法可以接受输入并打印输出:

打印输出:

  • Console.WriteLine ()
  • Console.Write ()

获取输入:

  • Console.ReadLine ()
  • Console.ReadKey ()
  • Console.Read ()

它们之间的区别是什么?参考文档

你也可能想找一个更好的网站开始学习c#。试试这个:

Visual c# .NET Programming

你可以在c#的书籍和资源中探索:

Stack Overflow c# Tag Wiki