简体   繁体   中英

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?)"

Note: I am not running this through Microsoft Visual Studio because the assignment involves running code through a text editor.

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".)

Any help is greatly appreciated!

Console.WriteLine("You entered the following {0} names " + "on the command line:", args.Length ); it should be Length

Length is a property. Properties are written in pascal case. Looks like you only have a typo in your second Console.WriteLine . There is an args. l ength with a lowercase l.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM