当我试图建立下列对象:问题进行初始化新对象
Tijdschrift tijdschrift = new Tijdschrift
{
Id = "ID01",
Titel = "Scientific American",
Datum = new DateTime(2014, 8, 1),
Uitgeverij = "Scientific American"
};
我收到以下错误:
Error CS7036 There is no argument given that corresponds to the required formal parameter 'Id' of 'Tijdschrift.Tijdschrift(string, string, DateTime, string)' Catalogus C:\Users\Robiin\Documents\Labo03\Labo03\Program.cs 13
我不知道为什么说实话,我的构造函数写成如下。
public Tijdschrift(string Id, string titel, DateTime datum, string uitgeverij)
{
Datum = datum;
this.Id = Id;
Titel = titel;
Uitgeverij = uitgeverij;
}
你感到困惑与构造函数的参数和属性初始化 – Luizgrs
您在使用使用不带参数的构造函数(换句话说,你是不是调用一个构造函数)对象初始化语法。相反,'新的Tijdschrift(“ID01”,...' – crashmstr
你能展示类'Tijdschrift'的相关部分(我的意思是所涉及的属性的声明) – Steve