我有一个直接来自我的教科书的非常简单的程序,用于打印您在命令行中键入的单词名称列表。
当我尝试运行代码时,出现一条错误,指出...
“错误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-Using Dev Prompt”之后开始。)
任何帮助是极大的赞赏!
最佳答案
Length
是一个属性。属性以帕斯卡大小写。
看起来您的第二个Console.WriteLine
中只有一个错字。有一个参数。 l ength,带有小写字母l。
关于c# - 为什么我的C#程序无法识别长度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54507572/