I have a class with two constructors. The empty constructor (no arguments) is not working.
The program does not display an error. One of the constructors receives the parameters nome
and limitedecredito
; and another, empty, initializes CPF
.
It turns out that the cpf
(TCPF) field is getting the value NULL
.
Client class constructor:
public Cliente():base()
{
}
Main Program:
(...)
case 1:
Console.Clear();
c1 = new Cliente();
Console.Write("CPF:");
CPF = Console.ReadLine();
if (c1.setCPF(CPF) == false)
{
Console.WriteLine("CPF inválido");
Console.ReadKey();
break;
}
Console.Write("Nome:");
string nome = Console.ReadLine();
Console.Write("Limite de credito R$:");
double limitecredito = double.Parse(Console.ReadLine());
c1 = new Cliente(nome, limitecredito);
LC.Add(c1);
Console.Write("Cadastro realizado com sucesso");
Console.ReadKey();
break;
(...)
Class Cliente
:
private double limitecredito;
public Cliente():base()
{
}
public Cliente(string n, double limitec) : base(n)
{
limitecredito = limitec;
}
Class Pessoa
(Mother):
private string nome;
private TCPF cpf;
public Pessoa()
{
cpf = new TCPF();
}
public Pessoa(string n)
{
cpf = new TCPF();
nome = n;
}
public string Nome
{
get { return nome; }
}
public bool setCPF(string X)
{
return cpf.ValidaCpf(X);
}
public string Cpf
{
get { return cpf.Cpf; }
}