簡體   English   中英

C#數組不打印出內容

[英]c# Array not printing out contents

我有一個數組,用戶將在其中插入5個職位,其中包括說明,完成工作所需的時間和小時工資。 對於新手問題,我感到很抱歉,因為我是這種語言的新手。 任何幫助,將不勝感激。

  private static void EnterJobs()
    {

        //string inputString;
        for (int i = 0; i < jobArray.Length; i++)
        {
            Job job = new Job();

            Console.WriteLine("Job " + i);

            Console.WriteLine("Enter a job description.");
            job.Description = Console.ReadLine();

            Console.WriteLine("Enter the amount of hours required to complete the job.");
            job.hoursToComplete = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("Enter the hourly rate for the job.");
            job.hourlyRate = Convert.ToInt32(Console.ReadLine());

            jobArray[i] = job;
        }

當我嘗試打印出數組的內容時,它會打印出

DemoJobs.Job
DemoJobs.Job
DemoJobs.Job
DemoJobs.Job
DemoJobs.Job

使用這個循環

        for (int i = 0; i < jobArray.Length; i++)
        {
            Console.WriteLine(jobArray[i]);
        }

我只是在記事本中記了一下,但是在Job類中,程序應該有類似以下內容的內容才能知道要打印的內容:

public override string ToString()
{
    return this.Description + ", Hours: " + this.Hours.ToString() + ", Rate: " + this.Rate.ToString(); 
}

那你就做

Console.WriteLine(job1.ToString());

暫無
暫無

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

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