为什么我的 C# 程序无法识别长度?

Why does my C# program not recognize length?

我有一个直接来自教科书的非常简单的程序,用于打印您在命令行中键入的单词名称列表。

当我尝试 运行 代码时,我收到一条错误消息...

"error CS1061: 'string[]' does not contain a definition for 'length' and no accessible extension method 'length' accepting a first argument of type 'string[]' could be found (are you missing a using directive or an assembly reference?)"

注意:我不是 运行通过 Microsoft Visual Studio 进行此操作,因为作业涉及通过文本编辑器 运行 进行代码。

代码在这里:

// Hello World2.cs
using System;

public class HelloWorld2
{
    public static void Main(string[] args)
    {
        Console.WriteLine("Hello, World.");
        Console.WriteLine("You entered the following {0} names " +
            "on the command line:", args.length );
        for (int i=0; i < args.Length; i++)
        {
            Console.WriteLine("{0}", args[i]);
        }
            Console.ReadKey(true);
    }
}

A link 给程序赋值 here.

(网页滚到一半,作业从标题"HelloWorld2 - Using Dev Prompt"后开始。)

非常感谢任何帮助!

Console.WriteLine("You entered the following {0} names " + "on the command line:", args.Length );它应该是长度

Length 是一个 属性。属性以 Pascal 大小写。 看起来你在第二个 Console.WriteLine 中只有一个错字。有一个 args.length 小写 l.