林是完全新的C#和试图建立在我创建的类/模型一个非常基本的应用程序:型号不包含一个构造函数8个参数
public class Customer
{
public int CustomerID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Address { get; set; }
public string Zipcode { get; set; }
public string City { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
}
现在,当我尝试实例化从另一个类的客户对象,像这样:
Customer c1 = new Customer(1, "Susan", "Peterson", "Borgergade 45", "8000", "Aarhus", "[email protected]", "21212121");
我得到:
'PetParadiseHotel.Models.Customer' 不包含一个常量 需要8个参数
从我的理解,应该有8个参数,所以这里有什么问题?
您的客户类有一个默认的构造函数(带有零个参数),因为您尚未声明它。试试'new Customer(){CustomerID = 1,FirstName =“Susan”,....};' – 2014-09-25 19:11:07
然后宣布它们会更好吗?那看起来怎么样? – Severin 2014-09-25 19:13:30
'public Customer(int customerId,....){this.CustomerID = customerId; ...}' – 2014-09-25 19:15:24