我有一个数组,其中用户将插入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]);
}
答案 0 :(得分:2)
我刚刚在记事本中记下了这一点,但是在你的Job类中你应该有类似以下内容的程序来知道要打印的内容:
public override string ToString()
{
return this.Description + ", Hours: " + this.Hours.ToString() + ", Rate: " + this.Rate.ToString();
}
然后你会做
Console.WriteLine(job1.ToString());