我的C#课程作业,但我无法弄清楚。 我想展示我的车,但它不起作用。 有人可以帮助我吗?
程序:
using System;
using System.Collections.Generic;
using System.Text;
namespace auto
{
class Program
{
static void Main(string[] args)
{
List<auto> autos = new List<auto>();
auto auto1 = new auto("Lamborgini" , "Aventador" , "2004");
display();
}
void display(List<auto> auto)
{
foreach (auto item in auto)
{
Console.WriteLine("Merk :" + item.merk );
Console.WriteLine("Model :" + item.model);
Console.WriteLine("Jaar :" + item.jaar);
Console.ReadKey();
}
}
}
}
类别:
using System;
using System.Collections.Generic;
using System.Text;
namespace auto
{
class auto
{
public string merk { get; set; }
public string model { get; set; }
public string jaar { get; set; }
public auto(string merk , string model, string jaar)
{
this.merk = merk;
this.model = model;
this.jaar = jaar;
}
}
}
这是我得到的错误:
严重级代码描述项目文件行抑制状态 错误CS7036没有给出符合所需形式参数&#39; auto&#39; &#39; Program.display(List)&#39;自动C:\ Users \ nickg \ source \ repos \ auto \ auto \ Program.cs 14 Active
答案 0 :(得分:1)
您将收到编译错误。所以你需要做的就是将参数传递给函数。
ListSelectionEvent
答案 1 :(得分:0)
使显示方法保持静态,并在调用时将autos
作为参数传递。
发布的代码使用auto
作为命名空间,类名和参数名,所以我怀疑编译器迟早会感到困惑。考虑给他们不同的名字。