Question

I'm trying to complete this task but when even though I believe I've invoked the method RecordCustomer() from SavingsAccount I'm getting an error that it's inaccessible due to its protection level, but I'm scratching my head trying to solve it.

class Customer
{
    private List<SavingsAccount> _Accounts = new List<SavingsAccount>();
    public ReadOnlyCollection<SavingsAccount> Accounts
    {
        get { return _Accounts.AsReadOnly(); }
    }

    public void AddAccount(SavingsAccount account) 
    {
        if (_Accounts.Contains(account) == false)
        {
            _Accounts.Add(account);
            account.RecordCustomer(this);
        }
    }

class SavingsAccount : Account
{
    public void RecordCustomer(Customer customer)
    {
         if (_Accounts.Contains(customer) == true && _Owners.Contains(customer) ==     false)
             _Owners.Add(customer);
    }
}

Thanks

Était-ce utile?

La solution

The issue you have is that the class is likely not accessible. By default, C# classes have the accessibility of internal, which means if the two classes you've shown are in the same assembly (i.e. the same project), then it will work. If they're not in the same assembly, then you will need to make SavingsAccount public.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top