错误表示卡和帐户字段从未分配给,但它们在默认构造函数中分配。我在这里错过了什么吗?
private string firstName, lastName;
private string address, number;
private Account account;
private Card card;
public Person()
{
firstName = "John";
lastName = "Doe";
address = "";
number = "02080000000";
account.AccountNumber = "0000";
card.CardNumber = "0000/0000/0000/0000";
card.PinNumber = "0000";
}
public Person(string FName, string LName, string Address, string Number, string AccNumber, string CardNumber, string PinNumber)
{
firstName = FName;
lastName = LName;
address = Address;
number = Number;
account.AccountNumber = AccNumber;
card.CardNumber = CardNumber;
card.PinNumber = PinNumber;
}
答案 0 :(得分:6)
首先需要创建它们,然后才将值分配给它们的属性。
private Account account = new Account();
private Card card = new Card();