【发布时间】:2025-12-13 00:20:04
【问题描述】:
我有一个非常简单的程序,直接来自我的教科书,用于打印您在命令行中键入的单词名称列表。
当我尝试运行代码时,我收到一条错误消息,指出...
"错误 CS1061: 'string[]' 不包含 'length' 的定义,并且找不到可访问的扩展方法 'length' 接受类型为 'string[]' 的第一个参数(您是否缺少 using 指令还是程序集参考?)”
注意:我没有通过 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);
}
}
指向程序分配here的链接。
(向下滚动网页一半,作业在标题“HelloWorld2 - 使用开发提示”之后开始。)
非常感谢任何帮助!
【问题讨论】:
-
length!=Length.
标签: c# arrays compiler-errors string-length