I have a problem in C #, I'm encountering an exception and I can not recognize why it is
Exception Details:
System.NullReferenceException: "Object reference not set to an instance of an object."
Excerpt of code that throws the exception is:
public void AdicionarCliente(String nome, String sobrenome)
{
Clientes.Add(new Cliente(nome, sobrenome));
}
In class:
public sealed class Banco
{
private static readonly Banco instance = new Banco();
public static Banco Instance
{
get
{
return instance;
}
}
private List<Cliente> Clientes;
private Banco()
{
}
public void AdicionarCliente(String nome, String sobrenome)
{
Clientes.Add(new Cliente(nome, sobrenome));
}
public int GetNumeroDeClientes()
{
return Clientes.Count;
}
public Cliente GetCliente(int indice)
{
return Clientes[indice];
}
}
Client Class:
public class Cliente
{
public String Nome
{
get;
private set;
}
public String Sobrenome
{
get;
private set;
}
private List<Conta> Contas { set; get; }
public Cliente(String nome, String sobrenome)
{
this.Nome = nome;
this.Sobrenome = sobrenome;
}
public Conta GetConta(int indice)
{
return Contas[indice];
}
public int GetNumeroDeContas()
{
return Contas.Count;
}
public void AdicionarConta(Conta c)
{
Contas.Add(c);
}
}