[英]Why does my C# program not recognize length?
I have a very simple program directly from my textbook that is meant to print a list of words names that you type to the command line. 我有一个非常简单的程序,直接来自我的教科书,旨在打印您在命令行中键入的单词名称列表。
When I try to run the code, I get an error that states... 当我尝试运行代码时,出现一条错误,指出...
"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?)" “错误CS1061:'string []'不包含'length'的定义,并且找不到可访问的扩展方法'length'接受类型为'string []'的第一个参数(您是否缺少using指令或程序集参考?)”
Note: I am not running this through Microsoft Visual Studio because the assignment involves running code through a text editor. 注意:我不是通过Microsoft Visual Studio运行此程序,因为分配涉及通过文本编辑器运行代码。
Code here: 代码在这里:
// 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 to the program assignment here . 此处指向程序分配的链接。
(Scroll halfway down the webpage, assignment starts after the title "HelloWorld2 - Using Dev Prompt".) (向下滚动到网页的一半,分配在标题“ HelloWorld2-Using Dev Prompt”之后开始。)
Any help is greatly appreciated! 任何帮助是极大的赞赏!
Console.WriteLine("You entered the following {0} names " + "on the command line:", args.Length ); Console.WriteLine(“您在命令行上输入了以下{0}名称” +“:args.Length); it should be Length
应该是长度
Length
is a property. Length
是一个属性。 Properties are written in pascal case. 属性以帕斯卡大小写。 Looks like you only have a typo in your second
Console.WriteLine
. 看起来您的第二个
Console.WriteLine
只有一个错字。 There is an args. 有一个参数。 l ength with a lowercase l.
我用小写字母l。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.