基本上我正在研究一个假设要复制银行业务的程序。有两个类,用户和帐户。我在用户帐户中创建了列表,该列表包含该用户的所有帐户。该列表存储由Account类构造函数收集的数据。我花了很多时间阅读其他人类似的问题,这让我达到了这一点,但我基本上被困了一个希望有人有一些建议。我正在尝试实现在用户类中创建的列表以在帐户类中工作,并且我认为我可能需要使用接口或子类。
class User
{
//fields
private int id;
public List<Account> _List;
//properties
public int Id
{
get { return id; }
}
public string Name { get; set; }
public string Username { get; set; }
public string Password { get; set; }
public List<Account> Acc
{
get { return _List; }
set { _List = value; }
}
//constructors
public User()
{
_List = new List<Account>();
Acc = new List<Account>();
}
public User(int ident, string name, string username, string password, string account)
{
id = ident;
Name = name;
Username = username;
Password = password;
account = Acc.ToString();
}
// methods
public void AddAccount()
{
Account a = new Account();
a.Acc = new List<Account>();
a.Acc.Add(new Account(11111, "Primary Checking Account", 22, 23, "" ));
a.Acc.Add(new Account(12345, "Primary Savings Account", 22, 23, ""));
a.Acc.Add(new Account(04587, "Secondary Checking Account", 22, 23,""));
a.Acc.Add(new Account(00222, "Secondary Savings Account", 22, 23, ""));
a.Acc.Add(new Account(12457, "College Savings Account", 22, 23, "" ));
a.Acc.Add(new Account(87442, "Rainy day Checking Account", 22, 23, ""));
}
public void DeleteAccount()
{
}
public void ObjectAccount()
{
}
public override string ToString()
{
return "null";
}
这是第二类
class Account
{
//fields
private int id;
private string name;
//properties
public int Id
{
get { return id; }
}
public string Name
{
get { return name; }
}
public int InitialBalance { get; set; }
public int InterestRate { get; set; }
public List<Account> Acc
{
get { return _List; } // this is where i am having the problem. I cant get the list called _List to exist in the account class.
set { _List = value; }
}
//Constructors
public Account()
{
_List = new List<Account>();
Acc = new List<Account>();
}// this is so the constructor can take 0 arguements.
public Account(int ident, string nam, int initialBalance, int interestRate, string account)
{
name = nam;
id = ident;
InitialBalance = initialBalance;
InterestRate = interestRate;
account = Acc.ToString();
}
public override string ToString()
{
return "null";
}
谢谢你的时间!
答案 0 :(得分:0)
我想不出您的帐户对象需要访问属于特定用户对象的帐户列表的充分理由。
如果您需要有关相关帐户的信息来执行某些操作/操作,我会
_List
)或