簡體   English   中英

為什么我的C#程序無法識別長度?

[英]Why does my C# program not recognize length?

我有一個非常簡單的程序,直接來自我的教科書,旨在打印您在命令行中鍵入的單詞名稱列表。

當我嘗試運行代碼時,出現一條錯誤,指出...

“錯誤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);
    }
}

此處指向程序分配的鏈接。

(向下滾動到網頁的一半,分配在標題“ HelloWorld2-Using Dev Prompt”之后開始。)

任何幫助是極大的贊賞!

Console.WriteLine(“您在命令行上輸入了以下{0}名稱” +“:args.Length); 應該是長度

Length是一個屬性。 屬性以帕斯卡大小寫。 看起來您的第二個Console.WriteLine只有一個錯字。 有一個參數。 用小寫字母l。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM